diff options
-rw-r--r-- | hash.c | 13 | ||||
-rw-r--r-- | test/ruby/test_hash.rb | 6 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 16 insertions, 5 deletions
@@ -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); diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 7832466ffb..738b058ca1 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -1664,9 +1664,15 @@ class TestHash < Test::Unit::TestCase def test_transform_values x = @cls[a: 1, b: 2, c: 3] + x.default = 42 y = x.transform_values {|v| v ** 2 } assert_equal([1, 4, 9], y.values_at(:a, :b, :c)) assert_not_same(x, y) + assert_nil(y.default) + + x.default_proc = proc {|h, k| k} + y = x.transform_values {|v| v ** 2 } + assert_nil(y.default_proc) y = x.transform_values.with_index {|v, i| "#{v}.#{i}" } assert_equal(%w(1.0 2.1 3.2), y.values_at(:a, :b, :c)) @@ -2,7 +2,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 1 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 114 +#define RUBY_PATCHLEVEL 115 #define RUBY_RELEASE_YEAR 2020 #define RUBY_RELEASE_MONTH 7 |