From 81c5c3c4d5ea706829652902679e82eed46182ca Mon Sep 17 00:00:00 2001 From: mrkn Date: Sat, 12 Nov 2016 02:24:32 +0000 Subject: rational.c: optimize Rational#== * rational.c (nurat_eqeq_p): optimize Rational#==. Author: Tadashi Saito * numeric.c (rb_int_equal): rename from int_equal and remove static to be exported. * internal.h (rb_int_equal): exported. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- rational.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'rational.c') diff --git a/rational.c b/rational.c index f7f508771b..afd6e5033a 100644 --- a/rational.c +++ b/rational.c @@ -1124,30 +1124,29 @@ nurat_eqeq_p(VALUE self, VALUE other) { get_dat1(self); - if (f_zero_p(dat->num) && f_zero_p(other)) + if (INT_ZERO_P(dat->num) && INT_ZERO_P(other)) return Qtrue; if (!FIXNUM_P(dat->den)) return Qfalse; if (FIX2LONG(dat->den) != 1) return Qfalse; - if (f_eqeq_p(dat->num, other)) - return Qtrue; - return Qfalse; + return rb_int_equal(dat->num, other); } } - else if (RB_TYPE_P(other, T_FLOAT)) { - return f_boolcast(f_eqeq_p(f_to_f(self), other)); + else if (RB_FLOAT_TYPE_P(other)) { + return f_boolcast(rb_dbl_cmp(nurat_to_double(self), RFLOAT_VALUE(other)) + == INT2FIX(0)); } else if (RB_TYPE_P(other, T_RATIONAL)) { { get_dat2(self, other); - if (f_zero_p(adat->num) && f_zero_p(bdat->num)) + if (INT_ZERO_P(adat->num) && INT_ZERO_P(bdat->num)) return Qtrue; - return f_boolcast(f_eqeq_p(adat->num, bdat->num) && - f_eqeq_p(adat->den, bdat->den)); + return f_boolcast(rb_int_equal(adat->num, bdat->num) && + rb_int_equal(adat->den, bdat->den)); } } else { -- cgit v1.2.3