diff --git a/internal.h b/internal.h index 4c26bd2c13..9c11f4a308 100644 --- a/internal.h +++ b/internal.h @@ -1342,6 +1342,7 @@ 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); +VALUE rb_float_eql(VALUE x, VALUE y); #if USE_FLONUM #define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n))) @@ -1619,6 +1620,7 @@ size_t rb_str_memsize(VALUE); VALUE rb_sym_proc_call(ID mid, int argc, const VALUE *argv, VALUE passed_proc); VALUE rb_sym_to_proc(VALUE sym); char *rb_str_to_cstr(VALUE str); +VALUE rb_str_eql(VALUE str1, VALUE str2); /* symbol.c */ #ifdef RUBY_ENCODING_H diff --git a/numeric.c b/numeric.c index 69bb573cc7..8205829f8d 100644 --- a/numeric.c +++ b/numeric.c @@ -1643,8 +1643,8 @@ flo_le(VALUE x, VALUE y) * so an implementation-dependent value is returned. */ -static VALUE -flo_eql(VALUE x, VALUE y) +VALUE +rb_float_eql(VALUE x, VALUE y) { if (RB_TYPE_P(y, T_FLOAT)) { double a = RFLOAT_VALUE(x); @@ -1658,6 +1658,8 @@ flo_eql(VALUE x, VALUE y) return Qfalse; } +#define flo_eql rb_float_eql + /* * call-seq: * float.to_f -> self diff --git a/string.c b/string.c index 8de556718e..54a89f3565 100644 --- a/string.c +++ b/string.c @@ -3183,7 +3183,7 @@ rb_str_equal(VALUE str1, VALUE str2) * Two strings are equal if they have the same length and content. */ -static VALUE +VALUE rb_str_eql(VALUE str1, VALUE str2) { if (str1 == str2) return Qtrue; diff --git a/vm_insnhelper.c b/vm_insnhelper.c index a23983a5e0..b9bfccac95 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1295,6 +1295,9 @@ check_cfunc(const rb_callable_method_entry_t *me, VALUE (*func)()) } } +#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) + static #ifndef NO_BIG_INLINE inline @@ -1302,8 +1305,6 @@ inline VALUE opt_eq_func(VALUE recv, VALUE obj, CALL_INFO ci, CALL_CACHE cc) { -#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; @@ -1324,8 +1325,47 @@ opt_eq_func(VALUE recv, VALUE obj, CALL_INFO ci, CALL_CACHE cc) return rb_str_equal(recv, obj); } } -#undef EQ_UNREDEFINED_P -#undef BUILTIN_CLASS_P + + { + vm_search_method(ci, cc, recv); + + if (check_cfunc(cc->me, rb_obj_equal)) { + return recv == obj ? Qtrue : Qfalse; + } + } + + return Qundef; +} + +static +#ifndef NO_BIG_INLINE +inline +#endif +VALUE +opt_eql_func(VALUE recv, VALUE obj, CALL_INFO ci, CALL_CACHE cc) +{ +#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)) { + 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_eql(recv, obj); + } + } + else if (BUILTIN_CLASS_P(recv, rb_cString)) { + if (EQ_UNREDEFINED_P(STRING)) { + return rb_str_eql(recv, obj); + } + } { vm_search_method(ci, cc, recv); @@ -1361,7 +1401,7 @@ rb_eql_opt(VALUE obj1, VALUE obj2) cc.method_state = 0; cc.class_serial = 0; cc.me = NULL; - return opt_eq_func(obj1, obj2, &ci, &cc); + return opt_eql_func(obj1, obj2, &ci, &cc); } static VALUE vm_call0(rb_thread_t*, VALUE, ID, int, const VALUE*, const rb_callable_method_entry_t *);