ruby-changes:62015
From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Mon, 29 Jun 2020 11:07:34 +0900 (JST)
Subject: [ruby-changes:62015] 5f60538245 (master): any_hash: do not goto into a branch
https://git.ruby-lang.org/ruby.git/commit/?id=5f60538245 From 5f6053824551aec947a1c53d08975595aca1e513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= <shyouhei@r...> Date: Mon, 15 Jun 2020 15:02:53 +0900 Subject: 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. diff --git a/hash.c b/hash.c index 3babff5..acb237c 100644 --- a/hash.c +++ b/hash.c @@ -190,36 +190,35 @@ any_hash(VALUE a, st_index_t (*other_func)(VALUE)) https://github.com/ruby/ruby/blob/trunk/hash.c#L190 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; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/