rational.c: removed redundant conditions
Fixnums can be compared by object values themselves only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1e30a7e001
commit
00f82af5ed
33
rational.c
33
rational.c
@ -58,9 +58,9 @@ f_##n(VALUE x)\
|
|||||||
inline static VALUE
|
inline static VALUE
|
||||||
f_add(VALUE x, VALUE y)
|
f_add(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
if (FIXNUM_P(y) && FIXNUM_ZERO_P(y))
|
if (FIXNUM_ZERO_P(y))
|
||||||
return x;
|
return x;
|
||||||
else if (FIXNUM_P(x) && FIXNUM_ZERO_P(x))
|
if (FIXNUM_ZERO_P(x))
|
||||||
return y;
|
return y;
|
||||||
return rb_funcall(x, '+', 1, y);
|
return rb_funcall(x, '+', 1, y);
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ f_add(VALUE x, VALUE y)
|
|||||||
inline static VALUE
|
inline static VALUE
|
||||||
f_div(VALUE x, VALUE y)
|
f_div(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
if (FIXNUM_P(y) && FIX2LONG(y) == 1)
|
if (y == ONE)
|
||||||
return x;
|
return x;
|
||||||
if (RB_INTEGER_TYPE_P(x))
|
if (RB_INTEGER_TYPE_P(x))
|
||||||
return rb_int_div(x, y);
|
return rb_int_div(x, y);
|
||||||
@ -91,26 +91,13 @@ binop(mod, '%')
|
|||||||
inline static VALUE
|
inline static VALUE
|
||||||
f_mul(VALUE x, VALUE y)
|
f_mul(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
if (FIXNUM_P(y)) {
|
if (FIXNUM_ZERO_P(y) && RB_INTEGER_TYPE_P(x))
|
||||||
long iy = FIX2LONG(y);
|
return ZERO;
|
||||||
if (iy == 0) {
|
if (y == ONE) return x;
|
||||||
if (RB_INTEGER_TYPE_P(x))
|
if (FIXNUM_ZERO_P(x) && RB_INTEGER_TYPE_P(y))
|
||||||
return ZERO;
|
return ZERO;
|
||||||
}
|
if (x == ONE) return y;
|
||||||
else if (iy == 1)
|
else if (RB_INTEGER_TYPE_P(x))
|
||||||
return x;
|
|
||||||
}
|
|
||||||
else if (FIXNUM_P(x)) {
|
|
||||||
long ix = FIX2LONG(x);
|
|
||||||
if (ix == 0) {
|
|
||||||
if (RB_INTEGER_TYPE_P(y))
|
|
||||||
return ZERO;
|
|
||||||
}
|
|
||||||
else if (ix == 1)
|
|
||||||
return y;
|
|
||||||
return rb_int_mul(x, y);
|
|
||||||
}
|
|
||||||
else if (RB_TYPE_P(x, T_BIGNUM))
|
|
||||||
return rb_int_mul(x, y);
|
return rb_int_mul(x, y);
|
||||||
return rb_funcall(x, '*', 1, y);
|
return rb_funcall(x, '*', 1, y);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user