mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
vm.c: simplified core#hash_merge_kwd
* vm.c (core_hash_merge_kwd): simplified to merge the second hash into the first hash. * compile.c (compile_array): call core#hash_merge_kwd with 2 hashes always, by passing an new empty hash to at the first iteration. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8d004ee5fb
commit
aec14b33d4
2 changed files with 8 additions and 22 deletions
|
@ -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;
|
||||
|
|
25
vm.c
25
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);
|
||||
|
|
Loading…
Reference in a new issue