diff options
author | 卜部昌平 <[email protected]> | 2020-06-11 13:23:56 +0900 |
---|---|---|
committer | 卜部昌平 <[email protected]> | 2020-06-29 11:05:41 +0900 |
commit | 8d182b04ed04378877e743535658be41a05aef74 () | |
tree | b40c196d5a7fbb49368bb233c941c70aaea49257 /builtin.c | |
parent | 9ec4f1f205f7106e7b2e82abd69dbbc58978c586 (diff) |
builtin_lookup: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
Notes: Merged: https://.com/ruby/ruby/pull/3247
-rw-r--r-- | builtin.c | 28 |
1 files changed, 14 insertions, 14 deletions
@@ -12,27 +12,24 @@ #include "builtin_binary.inc" static const unsigned char* builtin_lookup(const char *feature, size_t *psize) { 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); } void @@ -41,6 +38,9 @@ rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin // search binary size_t size; const unsigned char *bin = builtin_lookup(feature_name, &size); // load binary rb_vm_t *vm = GET_VM(); |