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.
This commit is contained in:
卜部昌平 2020-06-16 10:56:56 +09:00
Родитель 268962077a
Коммит 06ed9a7a04
1 изменённых файлов: 14 добавлений и 12 удалений

Просмотреть файл

@ -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;