diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-06-16 10:56:56 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-06-29 11:05:41 +0900 |
commit | 06ed9a7a045ab4a1e2e98910b06b988e6434fc44 (patch) | |
tree | d0486ab1591eb57140e059b2f369ecf970396817 /object.c | |
parent | 268962077a84d4d24401986af56992aeb39a8146 (diff) | |
download | ruby-06ed9a7a045ab4a1e2e98910b06b988e6434fc44.tar.gz |
rb_convert_to_integer: 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 'object.c')
-rw-r--r-- | object.c | 26 |
1 files changed, 14 insertions, 12 deletions
@@ -3362,33 +3362,35 @@ rb_convert_to_integer(VALUE val, int base, int raise_exception) { VALUE tmp; + if (base) { + tmp = rb_check_string_type(val); + + if (! NIL_P(tmp)) { + val = tmp; + } + else if (! raise_exception) { + return Qnil; + } + else { + rb_raise(rb_eArgError, "base specified for non string value"); + } + } if (RB_FLOAT_TYPE_P(val)) { - double f; - if (base != 0) goto arg_error; - f = RFLOAT_VALUE(val); + double f = RFLOAT_VALUE(val); if (!raise_exception && !isfinite(f)) return Qnil; if (FIXABLE(f)) return LONG2FIX((long)f); return rb_dbl2big(f); } else if (RB_INTEGER_TYPE_P(val)) { - if (base != 0) goto arg_error; return val; } else if (RB_TYPE_P(val, T_STRING)) { return rb_str_convert_to_inum(val, base, TRUE, raise_exception); } else if (NIL_P(val)) { - if (base != 0) goto arg_error; if (!raise_exception) return Qnil; rb_raise(rb_eTypeError, "can't convert nil into Integer"); } - if (base != 0) { - tmp = rb_check_string_type(val); - if (!NIL_P(tmp)) return rb_str_convert_to_inum(tmp, base, TRUE, raise_exception); - arg_error: - if (!raise_exception) return Qnil; - rb_raise(rb_eArgError, "base specified for non string value"); - } tmp = rb_protect(rb_check_to_int, val, NULL); if (RB_INTEGER_TYPE_P(tmp)) return tmp; |