diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-12 01:29:01 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-12 01:29:01 +0000 |
commit | fb40c3776a1d339ce78f24fc913e425e780891e7 (patch) | |
tree | 36e2a3494e07bd185429b0f523c3bfd36a69fb7d /rational.c | |
parent | d8769bffe590bad0a9d65cb796c622fb819feeb2 (diff) |
rational.c: optimize Rational#<=>
* rational.c (nurat_cmp): optimize Rational#<=>.
Author: Tadashi Saito <[email protected]>
* numeric.c (rb_int_cmp): rename from int_cmp and remove static
to be exported.
* internal.h (rb_int_cmp): exported.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'rational.c')
-rw-r--r-- | rational.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/rational.c b/rational.c index 4592178b7f..f7f508771b 100644 --- a/rational.c +++ b/rational.c @@ -1072,15 +1072,17 @@ nurat_cmp(VALUE self, VALUE other) { get_dat1(self); - if (FIXNUM_P(dat->den) && FIX2LONG(dat->den) == 1) - return f_cmp(dat->num, other); /* c14n */ - return f_cmp(self, f_rational_new_bang1(CLASS_OF(self), other)); + if (dat->den == LONG2FIX(1)) + return rb_int_cmp(dat->num, other); /* c14n */ + other = f_rational_new_bang1(CLASS_OF(self), other); + goto other_is_rational; } } - else if (RB_TYPE_P(other, T_FLOAT)) { - return f_cmp(f_to_f(self), other); + else if (RB_FLOAT_TYPE_P(other)) { + 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; @@ -1092,10 +1094,10 @@ nurat_cmp(VALUE self, VALUE other) num2 = f_imul(FIX2LONG(bdat->num), FIX2LONG(adat->den)); } else { - num1 = f_mul(adat->num, bdat->den); - num2 = f_mul(bdat->num, adat->den); + num1 = rb_int_mul(adat->num, bdat->den); + num2 = rb_int_mul(bdat->num, adat->den); } - return f_cmp(f_sub(num1, num2), ZERO); + return rb_int_cmp(rb_int_minus(num1, num2), ZERO); } } else { |