From 8d182b04ed04378877e743535658be41a05aef74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Thu, 11 Jun 2020 13:23:56 +0900 Subject: [PATCH] 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. --- builtin.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/builtin.c b/builtin.c index 6de77228d0..7c3653dab7 100644 --- a/builtin.c +++ b/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