summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-24 15:28:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-24 15:28:31 +0000
commit4765f9c774300333d06397543625e163f2d6014a (patch)
treef334207ec3b0c17d7d64eee85049d3d2f19e00f0 /vm.c
parentd617a02b14b170219eb0f4b0cff23360e6fb4fc4 (diff)
vm.c: extract core_hash_merge
* vm.c (core_hash_merge): extract from m_core_hash_merge_ary and m_core_hash_merge_ptr. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/vm.c b/vm.c
index b0597af..5b4aa6f 100644
--- a/vm.c
+++ b/vm.c
@@ -2253,6 +2253,18 @@ m_core_set_postexe(VALUE self)
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();
@@ -2267,25 +2279,16 @@ m_core_hash_from_ary(VALUE self, VALUE 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_AREF(ary, i), RARRAY_AREF(ary, i+1));
- }
-
+ core_hash_merge(hash, RARRAY_LEN(ary), RARRAY_CONST_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;
}