Skip to content

Commit

Permalink
Use binary search for special casing map search
Browse files Browse the repository at this point in the history
  • Loading branch information
seven1m committed Jun 5, 2024
1 parent ca675f5 commit d7165be
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/encoding_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,19 @@ uint8_t EncodingObject::codepoint_to_titlecase(nat_int_t codepoint, nat_int_t re
}

SpecialCasingEntry EncodingObject::find_special_casing_map_entry(nat_int_t codepoint) {
// FIXME: do a binary search
for (int i = 0; i < special_casing_map_size; i++) {
if (special_casing_map[i].code == codepoint)
return special_casing_map[i];
int low = 0;
int high = special_casing_map_size - 1;

while (low <= high) {
int mid = low + (high - low) / 2;
if (special_casing_map[mid].code == codepoint)
return special_casing_map[mid];
if (special_casing_map[mid].code < codepoint)
low = mid + 1;
else
high = mid - 1;
}

return {};
}

Expand Down

0 comments on commit d7165be

Please sign in to comment.