mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
opt_eq_func refactor
* vm_insnhelper.c (opt_eq_func): method to dispatch is resolved by only the receiver's class, not including the argument class. even if basic operation is redefined, other class conditions never meet. optimize Float and non-Float case, delegate to rb_float_equal directly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3106f9412a
commit
63f298b0c1
3 changed files with 24 additions and 24 deletions
|
@ -1307,6 +1307,7 @@ VALUE rb_int_lshift(VALUE x, VALUE y);
|
|||
VALUE rb_int_div(VALUE x, VALUE y);
|
||||
VALUE rb_int_abs(VALUE num);
|
||||
VALUE rb_float_abs(VALUE flt);
|
||||
VALUE rb_float_equal(VALUE x, VALUE y);
|
||||
|
||||
#if USE_FLONUM
|
||||
#define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n)))
|
||||
|
|
|
@ -1418,8 +1418,8 @@ num_equal(VALUE x, VALUE y)
|
|||
*
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
flo_eq(VALUE x, VALUE y)
|
||||
VALUE
|
||||
rb_float_equal(VALUE x, VALUE y)
|
||||
{
|
||||
volatile double a, b;
|
||||
|
||||
|
@ -1442,6 +1442,8 @@ flo_eq(VALUE x, VALUE y)
|
|||
return (a == b)?Qtrue:Qfalse;
|
||||
}
|
||||
|
||||
#define flo_eq rb_float_equal
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* float.hash -> integer
|
||||
|
|
|
@ -1265,32 +1265,29 @@ inline
|
|||
VALUE
|
||||
opt_eq_func(VALUE recv, VALUE obj, CALL_INFO ci, CALL_CACHE cc)
|
||||
{
|
||||
if (FIXNUM_2_P(recv, obj) &&
|
||||
BASIC_OP_UNREDEFINED_P(BOP_EQ, INTEGER_REDEFINED_OP_FLAG)) {
|
||||
#define BUILTIN_CLASS_P(x, k) (!SPECIAL_CONST_P(x) && RBASIC_CLASS(x) == k)
|
||||
#define EQ_UNREDEFINED_P(t) BASIC_OP_UNREDEFINED_P(BOP_EQ, t##_REDEFINED_OP_FLAG)
|
||||
if (FIXNUM_2_P(recv, obj)) {
|
||||
if (EQ_UNREDEFINED_P(INTEGER)) {
|
||||
return (recv == obj) ? Qtrue : Qfalse;
|
||||
}
|
||||
else if (FLONUM_2_P(recv, obj) &&
|
||||
BASIC_OP_UNREDEFINED_P(BOP_EQ, FLOAT_REDEFINED_OP_FLAG)) {
|
||||
}
|
||||
else if (FLONUM_2_P(recv, obj)) {
|
||||
if (EQ_UNREDEFINED_P(FLOAT)) {
|
||||
return (recv == obj) ? Qtrue : Qfalse;
|
||||
}
|
||||
else if (!SPECIAL_CONST_P(recv) && !SPECIAL_CONST_P(obj)) {
|
||||
if (RBASIC_CLASS(recv) == rb_cFloat &&
|
||||
RBASIC_CLASS(obj) == rb_cFloat &&
|
||||
BASIC_OP_UNREDEFINED_P(BOP_EQ, FLOAT_REDEFINED_OP_FLAG)) {
|
||||
double a = RFLOAT_VALUE(recv);
|
||||
double b = RFLOAT_VALUE(obj);
|
||||
|
||||
if (isnan(a) || isnan(b)) {
|
||||
return Qfalse;
|
||||
}
|
||||
return (a == b) ? Qtrue : Qfalse;
|
||||
else if (BUILTIN_CLASS_P(recv, rb_cFloat)) {
|
||||
if (EQ_UNREDEFINED_P(FLOAT)) {
|
||||
return rb_float_equal(recv, obj);
|
||||
}
|
||||
else if (RBASIC_CLASS(recv) == rb_cString &&
|
||||
RBASIC_CLASS(obj) == rb_cString &&
|
||||
BASIC_OP_UNREDEFINED_P(BOP_EQ, STRING_REDEFINED_OP_FLAG)) {
|
||||
}
|
||||
else if (BUILTIN_CLASS_P(recv, rb_cString)) {
|
||||
if (EQ_UNREDEFINED_P(STRING)) {
|
||||
return rb_str_equal(recv, obj);
|
||||
}
|
||||
}
|
||||
#undef EQ_UNREDEFINED_P
|
||||
|
||||
{
|
||||
vm_search_method(ci, cc, recv);
|
||||
|
|
Loading…
Reference in a new issue