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:
parent
d617a02b14
commit
4765f9c774
1 changed files with 14 additions and 11 deletions
25
vm.c
25
vm.c
|
@ -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
|
||||
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)
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue