aboutsummaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-01-10 21:26:43 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-01-10 21:44:38 +0900
commit1b4d406e3a04032b6d01e92b6d184a16945c6ac3 (patch)
treeda86f3fc92961cb4d675f6dad2b33ee5f7d96e8e /hash.c
parent135b533e84ea04d0a494422efba635e5c9f2bfb2 (diff)
downloadruby-1b4d406e3a04032b6d01e92b6d184a16945c6ac3.tar.gz
Hash#transform_values should return a plain new Hash
[Bug #16498]
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/hash.c b/hash.c
index 4f72b4ca36..f68eaaabd4 100644
--- a/hash.c
+++ b/hash.c
@@ -1549,10 +1549,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);
@@ -1562,6 +1560,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)
{
@@ -3213,7 +3218,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, 0);