Skip to content

Commit a0f4795

Browse files
committed
[api] Fix table performance issues with 64bit keys.
1 parent 46b8cbf commit a0f4795

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

lib/bl/api/extra/draw/draw.bl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,14 +648,15 @@ get_character_count_to_fit :: fn (text: string_view, font: *Font, fit_to: f32, s
648648
space_glyph :: get_glyph_utf32(font, cast(u32) ' ');
649649
loop converted_bytes < text.len {
650650
rest :: str_sub(text, converted_bytes);
651+
651652
glyph: *GlyphInfo;
652653
if rest[0] == '\t' {
653654
w += space_glyph.advance_x * auto font.tab_size;
654655
converted_bytes += 1;
655656
} else if split_by_words && rest[0] == ' ' {
656657
w += space_glyph.advance_x;
657-
last_space_position = converted_bytes;
658658
converted_bytes += 1;
659+
last_space_position = converted_bytes; // Include the space at the end of the split.
659660
} else {
660661
utf32char, decoded_bytes, err_decode := utf8_to_utf32_single_char(rest);
661662
if err_decode {
@@ -666,6 +667,7 @@ get_character_count_to_fit :: fn (text: string_view, font: *Font, fit_to: f32, s
666667
glyph = get_glyph_utf32(font, utf32char);
667668
w += glyph.advance_x;
668669
}
670+
669671
if w > fit_to {
670672
if last_space_position > 0 {
671673
return last_space_position;

lib/bl/api/std/table/table.bl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,18 @@ calculate_hash :: fn (key: ?T) u32 #inline {
214214
} else {
215215
// copy-paste from stack overflow, is it good or not???
216216
// https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key
217-
#if true {
217+
#if sizeof(T) == 8 {
218+
x: u64 = auto key;
219+
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
220+
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
221+
x = x ^ (x >> 31);
222+
hash = auto x;
223+
} else {
218224
x: u32 = auto key;
219225
x = ((x >> 16) ^ x) * 0x45d9f3b;
220226
x = ((x >> 16) ^ x) * 0x45d9f3b;
221227
x = (x >> 16) ^ x;
222228
hash = x;
223-
} else {
224-
x: u32 = auto key;
225-
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
226-
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
227-
x = x ^ (x >> 31);
228-
hash = x;
229229
}
230230
}
231231
return hash;

0 commit comments

Comments
 (0)