mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
1 changed files with 15 additions and 4 deletions
19
builtin.c
19
builtin.c
|
@ -15,10 +15,21 @@
|
|||
static const unsigned char*
|
||||
builtin_lookup(const char *feature, size_t *psize)
|
||||
{
|
||||
for (int i=0; i<BUILTIN_BINARY_SIZE; i++) {
|
||||
if (strcmp(builtin_binary[i].feature, feature) == 0) {
|
||||
*psize = builtin_binary[i].bin_size;
|
||||
return builtin_binary[i].bin;
|
||||
static int index = 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;
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue