diff --git a/benchmark/vm_case_classes.yml b/benchmark/vm_case_classes.yml new file mode 100644 index 0000000000..cacc4f0464 --- /dev/null +++ b/benchmark/vm_case_classes.yml @@ -0,0 +1,9 @@ +benchmark: + vm_case_classes: | + case :foo + when Hash + raise + when Array + raise + end +loop_count: 6000000 diff --git a/compile.c b/compile.c index e8d5d0514f..b03e815229 100644 --- a/compile.c +++ b/compile.c @@ -4572,8 +4572,6 @@ when_vals(rb_iseq_t *iseq, LINK_ANCHOR *const cond_seq, const NODE *vals, rb_hash_aset(literals, lit, (VALUE)(l1) | 1); } - ADD_INSN(cond_seq, val, dup); /* dup target */ - if (nd_type(val) == NODE_STR) { debugp_param("nd_lit", val->nd_lit); lit = rb_fstring(val->nd_lit); @@ -4584,7 +4582,9 @@ when_vals(rb_iseq_t *iseq, LINK_ANCHOR *const cond_seq, const NODE *vals, if (!COMPILE(cond_seq, "when cond", val)) return -1; } - ADD_INSN1(cond_seq, vals, checkmatch, INT2FIX(VM_CHECKMATCH_TYPE_CASE)); + // Emit patern === target + ADD_INSN1(cond_seq, vals, topn, INT2FIX(1)); + ADD_CALL(cond_seq, vals, idEqq, INT2FIX(1)); ADD_INSNL(cond_seq, val, branchif, l1); vals = vals->nd_next; } diff --git a/test/ruby/test_jit.rb b/test/ruby/test_jit.rb index 55922b2d8c..5b79f8c0ea 100644 --- a/test/ruby/test_jit.rb +++ b/test/ruby/test_jit.rb @@ -497,7 +497,7 @@ class TestJIT < Test::Unit::TestCase end def test_compile_insn_checkmatch_opt_case_dispatch - assert_compile_once("#{<<~"begin;"}\n#{<<~"end;"}", result_inspect: '"world"', insns: %i[checkmatch opt_case_dispatch]) + assert_compile_once("#{<<~"begin;"}\n#{<<~"end;"}", result_inspect: '"world"', insns: %i[opt_case_dispatch]) begin; case 'hello' when 'hello'