summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-13 03:16:54 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-13 03:16:54 +0000
commit0e040f8dbffad39dd7fc50e34ab5c90497c8ce38 (patch)
treed892f476f277c849c6b6946bb2f8a59ef6a257e4 /vm.c
parent060b4df0acb9ef7258ce7b0e9f23d4d3c8111a83 (diff)
compile.c, vm.c: reduce hash merge
* compile.c (compile_array_): no hash to merge if it is empty. * vm.c (m_core_hash_merge_kwd): just check keys if only one argument is given, without merging. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/vm.c b/vm.c
index 287d1c3..032bcdb 100644
--- a/vm.c
+++ b/vm.c
@@ -2221,11 +2221,22 @@ kwmerge_i(VALUE key, VALUE value, VALUE hash)
return ST_CONTINUE;
}
+static int
+kwcheck_i(VALUE key, VALUE value, VALUE hash)
+{
+ if (!SYMBOL_P(key)) Check_Type(key, T_SYMBOL);
+ return ST_CONTINUE;
+}
+
static VALUE
-m_core_hash_merge_kwd(VALUE recv, VALUE hash, VALUE kw)
+m_core_hash_merge_kwd(int argc, VALUE *argv, VALUE recv)
{
+ VALUE hash, kw;
+ rb_check_arity(argc, 1, 2);
+ hash = argv[0];
+ kw = argv[argc-1];
kw = rb_convert_type(kw, T_HASH, "Hash", "to_hash");
- rb_hash_foreach(kw, kwmerge_i, hash);
+ rb_hash_foreach(kw, argc < 2 ? kwcheck_i : kwmerge_i, hash);
return hash;
}
@@ -2301,7 +2312,7 @@ Init_VM(void)
rb_define_method_id(klass, id_core_hash_from_ary, m_core_hash_from_ary, 1);
rb_define_method_id(klass, id_core_hash_merge_ary, m_core_hash_merge_ary, 2);
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, 2);
+ rb_define_method_id(klass, id_core_hash_merge_kwd, m_core_hash_merge_kwd, -1);
rb_define_method_id(klass, idProc, rb_block_proc, 0);
rb_define_method_id(klass, idLambda, rb_block_lambda, 0);
rb_obj_freeze(fcore);