ruby-changes:46767
From: nobu <ko1@a...>
Date: Thu, 25 May 2017 14:29:41 +0900 (JST)
Subject: [ruby-changes:46767] nobu:r58882 (trunk): vm_insnhelper.c: rb_eql_opt should call eql?
nobu 2017-05-25 14:29:35 +0900 (Thu, 25 May 2017) New Revision: 58882 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58882 Log: vm_insnhelper.c: rb_eql_opt should call eql? * vm_insnhelper.c (rb_eql_opt): should call #eql? on Float and String, not #==. Modified files: trunk/internal.h trunk/numeric.c trunk/string.c trunk/vm_insnhelper.c Index: string.c =================================================================== --- string.c (revision 58881) +++ string.c (revision 58882) @@ -3183,7 +3183,7 @@ rb_str_equal(VALUE str1, VALUE str2) https://github.com/ruby/ruby/blob/trunk/string.c#L3183 * 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; Index: internal.h =================================================================== --- internal.h (revision 58881) +++ internal.h (revision 58882) @@ -1342,6 +1342,7 @@ VALUE rb_int_div(VALUE x, VALUE y); https://github.com/ruby/ruby/blob/trunk/internal.h#L1342 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); https://github.com/ruby/ruby/blob/trunk/internal.h#L1620 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 Index: numeric.c =================================================================== --- numeric.c (revision 58881) +++ numeric.c (revision 58882) @@ -1643,8 +1643,8 @@ flo_le(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1643 * 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) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1658 return Qfalse; } +#define flo_eql rb_float_eql + /* * call-seq: * float.to_f -> self Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 58881) +++ vm_insnhelper.c (revision 58882) @@ -1295,6 +1295,9 @@ check_cfunc(const rb_callable_method_ent https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1295 } } +#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 https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1305 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_ https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1325 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) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1401 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 *); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/