diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-06-30 18:02:23 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-06-30 18:02:23 +0000 |
commit | 09cf4529269953847723eac4475bfe07c60b028a (patch) | |
tree | 2194d655a03c6e717c054338c7e8d2db1bc83409 /vm.c | |
parent | 370e83b789076bbada251c3a6cf8e38932a17883 (diff) |
merge revision(s) r45399,r45400,r46036,r46037: [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_1@46628 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 58 |
1 files changed, 41 insertions, 17 deletions
@@ -2262,46 +2262,62 @@ m_core_set_postexe(VALUE self) return Qnil; } +static VALUE core_hash_merge_ary(VALUE hash, VALUE ary); +static VALUE core_hash_from_ary(VALUE ary); +static VALUE core_hash_merge_kwd(int argc, VALUE *argv); + +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; + REWIND_CFP(hash = core_hash_from_ary(ary)); + return hash; +} + +static VALUE +core_hash_from_ary(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_AREF(ary, i), RARRAY_AREF(ary, i+1)); - } - - return hash; + return core_hash_merge_ary(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_AREF(ary, i), RARRAY_AREF(ary, i+1)); - } + REWIND_CFP(core_hash_merge_ary(hash, ary)); + return hash; +} +static VALUE +core_hash_merge_ary(VALUE hash, VALUE ary) +{ + 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]); - } + REWIND_CFP(core_hash_merge(hash, argc-1, argv+1)); return hash; } @@ -2334,6 +2350,14 @@ kwcheck_i(VALUE key, VALUE value, VALUE hash) static VALUE m_core_hash_merge_kwd(int argc, VALUE *argv, VALUE recv) { + VALUE hash; + REWIND_CFP(hash = core_hash_merge_kwd(argc, argv)); + return hash; +} + +static VALUE +core_hash_merge_kwd(int argc, VALUE *argv) +{ VALUE hash, kw; rb_check_arity(argc, 1, 2); hash = argv[0]; |