aboutsummaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2019-12-11 15:45:23 +0900
committerKoichi Sasada <ko1@atdot.net>2019-12-11 15:48:30 +0900
commit7f5014e6e884d7fa091e3e6462827b910417267c (patch)
treeef1f95c442875166d2d33ee263a33f8b66f5e655 /builtin.c
parent0afee4d80355dd03f0dfefe6120e2e1808d9cb50 (diff)
downloadruby-7f5014e6e884d7fa091e3e6462827b910417267c.tar.gz
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.
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/builtin.c b/builtin.c
index 304d7c2087..67b43c7f5c 100644
--- a/builtin.c
+++ b/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);