зеркало из https://github.com/github/ruby.git
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.
This commit is contained in:
Родитель
b5adaa8dbd
Коммит
5f60538245
37
hash.c
37
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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче