ruby-changes:46780
From: nobu <ko1@a...>
Date: Fri, 26 May 2017 15:28:44 +0900 (JST)
Subject: [ruby-changes:46780] nobu:r58896 (trunk): Symbol support for opt_eql_func too
nobu 2017-05-26 15:28:38 +0900 (Fri, 26 May 2017) New Revision: 58896 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58896 Log: Symbol support for opt_eql_func too * vm_insnhelper.c (comparable_by_identity): extract the condition where comparable by identity. currently both are same types, Fixnum, Flonum, or Symbol. * vm_insnhelper.c (opt_eql_func): support Symbol too. Modified files: trunk/vm_insnhelper.c Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 58895) +++ vm_insnhelper.c (revision 58896) @@ -1295,9 +1295,43 @@ check_cfunc(const rb_callable_method_ent https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1295 } } +static inline int +vm_method_cfunc_is(CALL_INFO ci, CALL_CACHE cc, + VALUE recv, VALUE (*func)()) +{ + vm_search_method(ci, cc, recv); + return check_cfunc(cc->me, func); +} + +static VALUE +opt_equal_fallback(VALUE recv, VALUE obj, CALL_INFO ci, CALL_CACHE cc) +{ + if (vm_method_cfunc_is(ci, cc, recv, rb_obj_equal)) { + return recv == obj ? Qtrue : Qfalse; + } + + return Qundef; +} + #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) +/* 1: compare by identity, 0: not applicable, -1: redefined */ +static inline int +comparable_by_identity(VALUE recv, VALUE obj) +{ + if (FIXNUM_2_P(recv, obj)) { + return (EQ_UNREDEFINED_P(INTEGER) != 0) * 2 - 1; + } + if (FLONUM_2_P(recv, obj)) { + return (EQ_UNREDEFINED_P(FLOAT) != 0) * 2 - 1; + } + if (SYMBOL_P(recv) && SYMBOL_P(obj)) { + return (EQ_UNREDEFINED_P(SYMBOL) != 0) * 2 - 1; + } + return 0; +} + static #ifndef NO_BIG_INLINE inline @@ -1305,15 +1339,13 @@ inline https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1339 VALUE opt_eq_func(VALUE recv, VALUE obj, CALL_INFO ci, CALL_CACHE cc) { - if (FIXNUM_2_P(recv, obj)) { - if (EQ_UNREDEFINED_P(INTEGER)) { - return (recv == obj) ? Qtrue : Qfalse; - } + switch (comparable_by_identity(recv, obj)) { + case 1: + return (recv == obj) ? Qtrue : Qfalse; + case -1: + goto fallback; } - else if (FLONUM_2_P(recv, obj)) { - if (EQ_UNREDEFINED_P(FLOAT)) { - return (recv == obj) ? Qtrue : Qfalse; - } + if (0) { } else if (BUILTIN_CLASS_P(recv, rb_cFloat)) { if (EQ_UNREDEFINED_P(FLOAT)) { @@ -1325,21 +1357,9 @@ opt_eq_func(VALUE recv, VALUE obj, CALL_ https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1357 return rb_str_equal(recv, obj); } } - else if (SYMBOL_P(recv) && SYMBOL_P(obj)) { - if (EQ_UNREDEFINED_P(SYMBOL)) { - return (recv == obj) ? Qtrue : Qfalse; - } - } - - { - vm_search_method(ci, cc, recv); - - if (check_cfunc(cc->me, rb_obj_equal)) { - return recv == obj ? Qtrue : Qfalse; - } - } - return Qundef; + fallback: + return opt_equal_fallback(recv, obj, ci, cc); } static @@ -1349,15 +1369,13 @@ inline https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1369 VALUE opt_eql_func(VALUE recv, VALUE obj, CALL_INFO ci, CALL_CACHE cc) { - if (FIXNUM_2_P(recv, obj)) { - if (EQ_UNREDEFINED_P(INTEGER)) { - return (recv == obj) ? Qtrue : Qfalse; - } + switch (comparable_by_identity(recv, obj)) { + case 1: + return (recv == obj) ? Qtrue : Qfalse; + case -1: + goto fallback; } - else if (FLONUM_2_P(recv, obj)) { - if (EQ_UNREDEFINED_P(FLOAT)) { - return (recv == obj) ? Qtrue : Qfalse; - } + if (0) { } else if (BUILTIN_CLASS_P(recv, rb_cFloat)) { if (EQ_UNREDEFINED_P(FLOAT)) { @@ -1370,15 +1388,8 @@ opt_eql_func(VALUE recv, VALUE obj, CALL https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1388 } } - { - vm_search_method(ci, cc, recv); - - if (check_cfunc(cc->me, rb_obj_equal)) { - return recv == obj ? Qtrue : Qfalse; - } - } - - return Qundef; + fallback: + return opt_equal_fallback(recv, obj, ci, cc); } #undef BUILTIN_CLASS_P #undef EQ_UNREDEFINED_P @@ -3465,14 +3476,6 @@ vm_opt_mod(VALUE recv, VALUE obj) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3476 } } -static inline int -vm_method_cfunc_is(CALL_INFO ci, CALL_CACHE cc, - VALUE recv, VALUE (*func)()) -{ - vm_search_method(ci, cc, recv); - return check_cfunc(cc->me, func); -} - static VALUE vm_opt_neq(CALL_INFO ci, CALL_CACHE cc, CALL_INFO ci_eq, CALL_CACHE cc_eq, -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/