From 921d6e269df182c3d9ab31f4bc084f5898d811e4 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 9 Mar 2016 07:17:02 +0000 Subject: 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 --- hash.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'hash.c') 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; } -- cgit v1.2.3