mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
rational.c: optimize Rational#==
* rational.c (nurat_eqeq_p): optimize Rational#==. Author: Tadashi Saito <tad.a.digger@gmail.com> * 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
This commit is contained in:
parent
fb40c3776a
commit
d611a7c77b
3 changed files with 13 additions and 13 deletions
|
@ -1174,6 +1174,7 @@ double rb_int_fdiv_double(VALUE x, VALUE y);
|
|||
VALUE rb_int_pow(VALUE x, VALUE y);
|
||||
VALUE rb_float_pow(VALUE x, VALUE y);
|
||||
VALUE rb_int_cmp(VALUE x, VALUE y);
|
||||
VALUE rb_int_equal(VALUE x, VALUE y);
|
||||
|
||||
#if USE_FLONUM
|
||||
#define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n)))
|
||||
|
|
|
@ -3971,8 +3971,8 @@ fix_equal(VALUE x, VALUE y)
|
|||
}
|
||||
}
|
||||
|
||||
static VALUE
|
||||
int_equal(VALUE x, VALUE y)
|
||||
VALUE
|
||||
rb_int_equal(VALUE x, VALUE y)
|
||||
{
|
||||
if (FIXNUM_P(x)) {
|
||||
return fix_equal(x, y);
|
||||
|
@ -5255,8 +5255,8 @@ Init_Numeric(void)
|
|||
rb_define_method(rb_cInteger, "abs", int_abs, 0);
|
||||
rb_define_method(rb_cInteger, "magnitude", int_abs, 0);
|
||||
|
||||
rb_define_method(rb_cInteger, "===", int_equal, 1);
|
||||
rb_define_method(rb_cInteger, "==", int_equal, 1);
|
||||
rb_define_method(rb_cInteger, "===", rb_int_equal, 1);
|
||||
rb_define_method(rb_cInteger, "==", rb_int_equal, 1);
|
||||
rb_define_method(rb_cInteger, ">", int_gt, 1);
|
||||
rb_define_method(rb_cInteger, ">=", rb_int_ge, 1);
|
||||
rb_define_method(rb_cInteger, "<", int_lt, 1);
|
||||
|
|
17
rational.c
17
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 {
|
||||
|
|
Loading…
Reference in a new issue