From 63f298b0c1ec1909ec536ae2fbcbaeb1a8dcf878 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 6 Mar 2017 06:44:11 +0000 Subject: [PATCH] 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 --- internal.h | 1 + numeric.c | 6 ++++-- vm_insnhelper.c | 41 +++++++++++++++++++---------------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/internal.h b/internal.h index eebd31073c..8d99f9fd8a 100644 --- a/internal.h +++ b/internal.h @@ -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))) diff --git a/numeric.c b/numeric.c index 6afd95e896..3d2b501ab2 100644 --- a/numeric.c +++ b/numeric.c @@ -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 diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 9e8ea9c9a8..f04d8365ab 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -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)) { - return (recv == obj) ? Qtrue : Qfalse; - } - else if (FLONUM_2_P(recv, obj) && - BASIC_OP_UNREDEFINED_P(BOP_EQ, FLOAT_REDEFINED_OP_FLAG)) { - 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; +#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 (RBASIC_CLASS(recv) == rb_cString && - RBASIC_CLASS(obj) == rb_cString && - BASIC_OP_UNREDEFINED_P(BOP_EQ, STRING_REDEFINED_OP_FLAG)) { + } + else if (FLONUM_2_P(recv, obj)) { + if (EQ_UNREDEFINED_P(FLOAT)) { + return (recv == obj) ? Qtrue : Qfalse; + } + } + else if (BUILTIN_CLASS_P(recv, rb_cFloat)) { + if (EQ_UNREDEFINED_P(FLOAT)) { + return rb_float_equal(recv, obj); + } + } + 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);