summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-07 03:37:35 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-07 03:37:35 +0000
commit20666f4a4dcba1895cd083c379cd48e98e036631 (patch)
tree813e9524abd3a42db869be5616445987b3bd45a2 /vm.c
parentea0bf82630a1aa8ad6c56b9d50c297ba1aab6fb5 (diff)
merge revision(s) 45399,45400,46036,46037: [Backport #416]
vm.c: merge code * vm.c (m_core_hash_from_ary, m_core_hash_merge_ary): merge duplicated code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@46736 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/vm.c b/vm.c
index 3e25533b67..df8146113c 100644
--- a/vm.c
+++ b/vm.c
@@ -2137,46 +2137,44 @@ m_core_set_postexe(VALUE self, VALUE iseqval)
return Qnil;
}
+static VALUE m_core_hash_merge_ary(VALUE self, VALUE hash, VALUE ary);
+
+static VALUE
+core_hash_merge(VALUE hash, long argc, const VALUE *argv)
+{
+ long i;
+ assert(argc % 2 == 0);
+ for (i=0; i<argc; i+=2) {
+ rb_hash_aset(hash, argv[i], argv[i+1]);
+ }
+ return hash;
+}
+
static VALUE
m_core_hash_from_ary(VALUE self, VALUE ary)
{
VALUE hash = rb_hash_new();
- int i;
if (RUBY_DTRACE_HASH_CREATE_ENABLED()) {
RUBY_DTRACE_HASH_CREATE(RARRAY_LEN(ary), rb_sourcefile(), rb_sourceline());
}
- assert(RARRAY_LEN(ary) % 2 == 0);
- for (i=0; i<RARRAY_LEN(ary); i+=2) {
- rb_hash_aset(hash, RARRAY_PTR(ary)[i], RARRAY_PTR(ary)[i+1]);
- }
-
- return hash;
+ return m_core_hash_merge_ary(self, hash, ary);
}
static VALUE
m_core_hash_merge_ary(VALUE self, VALUE hash, VALUE ary)
{
- int i;
-
- assert(RARRAY_LEN(ary) % 2 == 0);
- for (i=0; i<RARRAY_LEN(ary); i+=2) {
- rb_hash_aset(hash, RARRAY_PTR(ary)[i], RARRAY_PTR(ary)[i+1]);
- }
-
+ core_hash_merge(hash, RARRAY_LEN(ary), RARRAY_PTR(ary));
return hash;
}
static VALUE
m_core_hash_merge_ptr(int argc, VALUE *argv, VALUE recv)
{
- int i;
VALUE hash = argv[0];
- for (i=1; i<argc; i+=2) {
- rb_hash_aset(hash, argv[i], argv[i+1]);
- }
+ core_hash_merge(hash, argc-1, argv+1);
return hash;
}