Faster binary search
This commit is contained in:
parent
729565b5ca
commit
f2c0f94e42
1 changed files with 25 additions and 28 deletions
23
src/Font.cpp
23
src/Font.cpp
|
@ -1073,13 +1073,19 @@ static Glyph* GetGlyph(Font *font, unsigned long unicode_value)
|
|||
size_t left = 0;
|
||||
size_t right = font->total_local_glyphs;
|
||||
|
||||
for (;;)
|
||||
while (right - left >= 2)
|
||||
{
|
||||
size_t index = (left + right) / 2;
|
||||
const size_t index = (left + right) / 2;
|
||||
|
||||
if (font->local_glyphs[index].unicode_value == unicode_value)
|
||||
if (font->local_glyphs[index].unicode_value > unicode_value)
|
||||
right = index;
|
||||
else
|
||||
left = index;
|
||||
}
|
||||
|
||||
if (font->local_glyphs[left].unicode_value == unicode_value)
|
||||
{
|
||||
const Glyph *local_glyph = &font->local_glyphs[index];
|
||||
const Glyph *local_glyph = &font->local_glyphs[left];
|
||||
|
||||
glyph->unicode_value = local_glyph->unicode_value;
|
||||
glyph->width = font->glyph_slot_width;
|
||||
|
@ -1096,15 +1102,6 @@ static Glyph* GetGlyph(Font *font, unsigned long unicode_value)
|
|||
|
||||
return glyph;
|
||||
}
|
||||
|
||||
if (index == left)
|
||||
break;
|
||||
|
||||
if (font->local_glyphs[index].unicode_value < unicode_value)
|
||||
left = index;
|
||||
else //if (font->local_glyphs[index].unicode_value > unicode_value)
|
||||
right = index;
|
||||
}
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
|
|
Loading…
Add table
Reference in a new issue