mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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.
This commit is contained in:
parent
9ec4f1f205
commit
8d182b04ed
Notes:
git
2020-06-29 11:07:14 +09:00
1 changed files with 14 additions and 14 deletions
28
builtin.c
28
builtin.c
|
@ -12,27 +12,24 @@
|
|||
|
||||
#include "builtin_binary.inc"
|
||||
|
||||
static const unsigned char *
|
||||
bin4feature(const struct builtin_binary *bb, const char *feature, size_t *psize)
|
||||
{
|
||||
*psize = bb->bin_size;
|
||||
return strcmp(bb->feature, feature) ? NULL : bb->bin;
|
||||
}
|
||||
|
||||
static const unsigned char*
|
||||
builtin_lookup(const char *feature, size_t *psize)
|
||||
{
|
||||
static int index = 0;
|
||||
int i = index++;
|
||||
const unsigned char *bin = bin4feature(&builtin_binary[index++], feature, psize);
|
||||
|
||||
// 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;
|
||||
for (const struct builtin_binary *bb = &builtin_binary[0]; bb->feature &&! bin; bb++) {
|
||||
bin = bin4feature(bb++, feature, psize);
|
||||
}
|
||||
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);
|
||||
return bin;
|
||||
}
|
||||
|
||||
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);
|
||||
if (! bin) {
|
||||
rb_bug("builtin_lookup: can not find %s\n", feature_name);
|
||||
}
|
||||
|
||||
// load binary
|
||||
rb_vm_t *vm = GET_VM();
|
||||
|
|
Loading…
Add table
Reference in a new issue