aboutsummaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-06-15 15:02:53 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-06-29 11:05:41 +0900
commit5f6053824551aec947a1c53d08975595aca1e513 (patch)
tree1f4eabe3a6832121064990d0316e62f54c571108 /hash.c
parentb5adaa8dbdd6ce929faf9e22badbf520e9b0850b (diff)
downloadruby-5f6053824551aec947a1c53d08975595aca1e513.tar.gz
any_hash: 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.
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/hash.c b/hash.c
index 3babff59f3..acb237c46c 100644
--- a/hash.c
+++ b/hash.c
@@ -190,36 +190,35 @@ any_hash(VALUE a, st_index_t (*other_func)(VALUE))
VALUE hval;
st_index_t hnum;
- if (SPECIAL_CONST_P(a)) {
+ switch (TYPE(a)) {
+ case T_SYMBOL:
if (STATIC_SYM_P(a)) {
hnum = a >> (RUBY_SPECIAL_SHIFT + ID_SCOPE_SHIFT);
hnum = rb_hash_start(hnum);
- goto out;
}
- else if (FLONUM_P(a)) {
- /* prevent pathological behavior: [Bug #10761] */
- goto flt;
- }
+ else {
+ hnum = RSYMBOL(a)->hashval;
+ }
+ break;
+ case T_FIXNUM:
+ case T_TRUE:
+ case T_FALSE:
+ case T_NIL:
hnum = rb_objid_hash((st_index_t)a);
- }
- else if (BUILTIN_TYPE(a) == T_STRING) {
+ break;
+ case T_STRING:
hnum = rb_str_hash(a);
- }
- else if (BUILTIN_TYPE(a) == T_SYMBOL) {
- hnum = RSYMBOL(a)->hashval;
- }
- else if (BUILTIN_TYPE(a) == T_BIGNUM) {
+ break;
+ case T_BIGNUM:
hval = rb_big_hash(a);
hnum = FIX2LONG(hval);
- }
- else if (BUILTIN_TYPE(a) == T_FLOAT) {
- flt:
+ break;
+ case T_FLOAT: /* prevent pathological behavior: [Bug #10761] */
hnum = rb_dbl_long_hash(rb_float_value(a));
- }
- else {
+ break;
+ default:
hnum = other_func(a);
}
- out:
#if SIZEOF_LONG < SIZEOF_ST_INDEX_T
if (hnum > 0)
hnum &= (unsigned long)-1 >> 2;