aboutsummaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-09 07:17:02 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-09 07:17:02 +0000
commitf3eaba208f503c3228d7edaac73e473263c3675f (patch)
tree53ee1b5732efd39e1825329fe1aeac66d7a886a1 /hash.c
parentc06b11b3c537d150c9be4a63894462a106317166 (diff)
downloadruby-f3eaba208f503c3228d7edaac73e473263c3675f.tar.gz
hash.c: hash_dup for rb_hash_to_h
* hash.c (rb_hash_to_h): share hash_dup to copy the contents and the default value/proc only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54056 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/hash.c b/hash.c
index 400c330743..e98c7eec97 100644
--- a/hash.c
+++ b/hash.c
@@ -1881,14 +1881,8 @@ static VALUE
rb_hash_to_h(VALUE hash)
{
if (rb_obj_class(hash) != rb_cHash) {
- VALUE ret = rb_hash_new();
- if (!RHASH_EMPTY_P(hash))
- RHASH(ret)->ntbl = st_copy(RHASH(hash)->ntbl);
- if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
- FL_SET(ret, HASH_PROC_DEFAULT);
- }
- RHASH_SET_IFNONE(ret, RHASH_IFNONE(hash));
- return ret;
+ const VALUE flags = RBASIC(hash)->flags;
+ hash = hash_dup(hash, rb_cHash, flags & HASH_PROC_DEFAULT);
}
return hash;
}