From 05c4c88767b54808cd1459a1d6da11179c422cfa Mon Sep 17 00:00:00 2001 From: nagachika Date: Sun, 26 Jul 2020 18:32:36 +0900 Subject: merge revision(s) 1b4d406e3a04032b6d01e92b6d184a16945c6ac3: [Backport #16498] [Backport #16914] Hash#transform_values should return a plain new Hash [Bug #16498] --- hash.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'hash.c') diff --git a/hash.c b/hash.c index dd78d2d8e1..4a3f2ff536 100644 --- a/hash.c +++ b/hash.c @@ -1558,10 +1558,8 @@ rb_hash_new_with_size(st_index_t size) } static VALUE -hash_dup(VALUE hash, VALUE klass, VALUE flags) +hash_copy(VALUE ret, VALUE hash) { - VALUE ret = hash_alloc_flags(klass, flags, - RHASH_IFNONE(hash)); if (!RHASH_EMPTY_P(hash)) { if (RHASH_AR_TABLE_P(hash)) ar_copy(ret, hash); @@ -1571,6 +1569,13 @@ hash_dup(VALUE hash, VALUE klass, VALUE flags) return ret; } +static VALUE +hash_dup(VALUE hash, VALUE klass, VALUE flags) +{ + return hash_copy(hash_alloc_flags(klass, flags, RHASH_IFNONE(hash)), + hash); +} + VALUE rb_hash_dup(VALUE hash) { @@ -3205,7 +3210,7 @@ rb_hash_transform_values(VALUE hash) VALUE result; RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size); - result = hash_dup(hash, rb_cHash, 0); + result = hash_copy(hash_alloc(rb_cHash), hash); if (!RHASH_EMPTY_P(hash)) { rb_hash_stlike_foreach_with_replace(result, transform_values_foreach_func, transform_values_foreach_replace, result); -- cgit v1.2.3