1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

rb_rational_cmp: 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 14:42:24 +09:00
parent 9c5804ac1c
commit d7eec15f8e
Notes: git 2020-06-29 11:06:52 +09:00

View file

@ -1085,21 +1085,19 @@ rb_rational_pow(VALUE self, VALUE other)
VALUE VALUE
rb_rational_cmp(VALUE self, VALUE other) rb_rational_cmp(VALUE self, VALUE other)
{ {
if (RB_INTEGER_TYPE_P(other)) { switch (TYPE(other)) {
case T_FIXNUM:
case T_BIGNUM:
{ {
get_dat1(self); get_dat1(self);
if (dat->den == LONG2FIX(1)) if (dat->den == LONG2FIX(1))
return rb_int_cmp(dat->num, other); /* c14n */ return rb_int_cmp(dat->num, other); /* c14n */
other = f_rational_new_bang1(CLASS_OF(self), other); other = f_rational_new_bang1(CLASS_OF(self), other);
goto other_is_rational; /* FALLTHROUGH */
} }
}
else if (RB_FLOAT_TYPE_P(other)) { case T_RATIONAL:
return rb_dbl_cmp(nurat_to_double(self), RFLOAT_VALUE(other));
}
else if (RB_TYPE_P(other, T_RATIONAL)) {
other_is_rational:
{ {
VALUE num1, num2; VALUE num1, num2;
@ -1116,8 +1114,11 @@ rb_rational_cmp(VALUE self, VALUE other)
} }
return rb_int_cmp(rb_int_minus(num1, num2), ZERO); return rb_int_cmp(rb_int_minus(num1, num2), ZERO);
} }
}
else { case T_FLOAT:
return rb_dbl_cmp(nurat_to_double(self), RFLOAT_VALUE(other));
default:
return rb_num_coerce_cmp(self, other, rb_intern("<=>")); return rb_num_coerce_cmp(self, other, rb_intern("<=>"));
} }
} }