diff --git a/compile.c b/compile.c index 21971830ea..ea6b74d18d 100644 --- a/compile.c +++ b/compile.c @@ -3989,18 +3989,17 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_ro } } if (kw) { - VALUE nhash = (i > 0 || !first) ? INT2FIX(2) : INT2FIX(1); if (!popped) { ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); if (i > 0 || !first) ADD_INSN(ret, line, swap); + else ADD_INSN1(ret, line, newhash, INT2FIX(0)); } COMPILE(ret, "keyword splat", kw); if (popped) { ADD_INSN(ret, line, pop); } else { - ADD_SEND(ret, line, id_core_hash_merge_kwd, nhash); - if (nhash == INT2FIX(1)) ADD_SEND(ret, line, rb_intern("dup"), INT2FIX(0)); + ADD_SEND(ret, line, id_core_hash_merge_kwd, INT2FIX(2)); } } first = 0; diff --git a/vm.c b/vm.c index efdbff9a23..112f4de0bd 100644 --- a/vm.c +++ b/vm.c @@ -2675,7 +2675,7 @@ m_core_set_postexe(VALUE self) static VALUE core_hash_merge_ary(VALUE hash, VALUE ary); static VALUE core_hash_from_ary(VALUE ary); -static VALUE core_hash_merge_kwd(int argc, VALUE *argv); +static VALUE core_hash_merge_kwd(VALUE hash, VALUE kw); static VALUE core_hash_merge(VALUE hash, long argc, const VALUE *argv) @@ -2746,30 +2746,17 @@ kwmerge_i(VALUE key, VALUE value, VALUE hash) return ST_CONTINUE; } -static int -kwcheck_i(VALUE key, VALUE value, VALUE hash) -{ - kw_check_symbol(key); - return ST_CONTINUE; -} - static VALUE -m_core_hash_merge_kwd(int argc, VALUE *argv, VALUE recv) +m_core_hash_merge_kwd(VALUE recv, VALUE hash, VALUE kw) { - VALUE hash; - REWIND_CFP(hash = core_hash_merge_kwd(argc, argv)); + REWIND_CFP(hash = core_hash_merge_kwd(hash, kw)); return hash; } static VALUE -core_hash_merge_kwd(int argc, VALUE *argv) +core_hash_merge_kwd(VALUE hash, VALUE kw) { - VALUE hash, kw; - rb_check_arity(argc, 1, 2); - hash = argv[0]; - kw = rb_to_hash_type(argv[argc-1]); - if (argc < 2) hash = kw; - rb_hash_foreach(kw, argc < 2 ? kwcheck_i : kwmerge_i, hash); + rb_hash_foreach(rb_to_hash_type(kw), kwmerge_i, hash); return hash; } @@ -2859,7 +2846,7 @@ Init_VM(void) rb_define_method_id(klass, id_core_hash_merge_ary, m_core_hash_merge_ary, 2); #endif rb_define_method_id(klass, id_core_hash_merge_ptr, m_core_hash_merge_ptr, -1); - rb_define_method_id(klass, id_core_hash_merge_kwd, m_core_hash_merge_kwd, -1); + rb_define_method_id(klass, id_core_hash_merge_kwd, m_core_hash_merge_kwd, 2); rb_define_method_id(klass, idProc, rb_block_proc, 0); rb_define_method_id(klass, idLambda, rb_block_lambda, 0); rb_obj_freeze(fcore);