rely on sorted compiled binary array.
`builtin_binary` is sorted by miniruby loading order and this loading order should be same on ruby. So we can believe sorted order of `builtin_binary` on boot time.
This commit is contained in:
parent
0afee4d803
commit
7f5014e6e8
15
builtin.c
15
builtin.c
@ -15,11 +15,22 @@
|
|||||||
static const unsigned char*
|
static const unsigned char*
|
||||||
builtin_lookup(const char *feature, size_t *psize)
|
builtin_lookup(const char *feature, size_t *psize)
|
||||||
{
|
{
|
||||||
for (int i=0; i<BUILTIN_BINARY_SIZE; i++) {
|
static int index = 0;
|
||||||
if (strcmp(builtin_binary[i].feature, feature) == 0) {
|
int i = index++;
|
||||||
|
|
||||||
|
// usually, `builtin_binary` order is loading order at miniruby.
|
||||||
|
if (LIKELY(strcmp(builtin_binary[i].feature, feature) == 0)) {
|
||||||
|
found:
|
||||||
*psize = builtin_binary[i].bin_size;
|
*psize = builtin_binary[i].bin_size;
|
||||||
return builtin_binary[i].bin;
|
return builtin_binary[i].bin;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (0) fprintf(stderr, "builtin_lookup: cached index miss (index:%d)\n", i);
|
||||||
|
for (i=0; i<BUILTIN_BINARY_SIZE; i++) {
|
||||||
|
if (strcmp(builtin_binary[i].feature, feature) == 0) {
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rb_bug("builtin_lookup: can not find %s\n", feature);
|
rb_bug("builtin_lookup: can not find %s\n", feature);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user