Update `presym_find` to use more efficient binary search.

parent eddd3249
...@@ -26,13 +26,20 @@ static const char *presym_table[] = { ...@@ -26,13 +26,20 @@ static const char *presym_table[] = {
static mrb_sym static mrb_sym
presym_find(const char *name) presym_find(const char *name)
{ {
/* use linear search for now */ int start = 0;
/* binary search should work better */ int end = MRB_PRESYM_MAX-1;
int i;
while (start<=end) {
for (i=0; presym_table[i]; i++) { int mid = (start+end)/2;
if (strcmp(presym_table[i], name)==0) int cmp = strcmp(name, presym_table[mid]);
return i+1;
if (cmp == 0) {
return mid+1;
} else if (cmp < 0) {
end = mid-1;
} else {
start = mid+1;
}
} }
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment