1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2014-03-24 15:28:31 +00:00
parent d617a02b14
commit 4765f9c774

25
vm.c
View file

@ -2252,6 +2252,18 @@ m_core_set_postexe(VALUE self)
static VALUE m_core_hash_merge_ary(VALUE self, VALUE hash, VALUE ary); 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 static VALUE
m_core_hash_from_ary(VALUE self, VALUE ary) m_core_hash_from_ary(VALUE self, VALUE ary)
{ {
@ -2267,25 +2279,16 @@ m_core_hash_from_ary(VALUE self, VALUE ary)
static VALUE static VALUE
m_core_hash_merge_ary(VALUE self, VALUE hash, VALUE ary) m_core_hash_merge_ary(VALUE self, VALUE hash, VALUE ary)
{ {
int i; core_hash_merge(hash, RARRAY_LEN(ary), RARRAY_CONST_PTR(ary));
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));
}
return hash; return hash;
} }
static VALUE static VALUE
m_core_hash_merge_ptr(int argc, VALUE *argv, VALUE recv) m_core_hash_merge_ptr(int argc, VALUE *argv, VALUE recv)
{ {
int i;
VALUE hash = argv[0]; VALUE hash = argv[0];
for (i=1; i<argc; i+=2) { core_hash_merge(hash, argc-1, argv+1);
rb_hash_aset(hash, argv[i], argv[i+1]);
}
return hash; return hash;
} }