mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* hash.c (initialize_copy): duping should rehash the hash.
* test/ruby/test_hash.rb: added a test to ensure rehash. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37248 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bff930ccf4
commit
a34a3c2caa
3 changed files with 19 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
Thu Oct 18 09:23:03 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||
|
||||
* hash.c (initialize_copy): duping should rehash the hash.
|
||||
|
||||
* test/ruby/test_hash.rb: added a test to ensure rehash.
|
||||
|
||||
Wed Oct 17 21:16:47 2012 Hiroshi Shirosaki <h.shirosaki@gmail.com>
|
||||
|
||||
* common.mk (WPROGRAM): need same dependencies as PROGRAM.
|
||||
|
|
5
hash.c
5
hash.c
|
@ -1187,8 +1187,11 @@ rb_hash_initialize_copy(VALUE hash, VALUE hash2)
|
|||
{
|
||||
Check_Type(hash2, T_HASH);
|
||||
|
||||
if (!RHASH_EMPTY_P(hash2))
|
||||
if (!RHASH_EMPTY_P(hash2)) {
|
||||
RHASH(hash)->ntbl = st_copy(RHASH(hash2)->ntbl);
|
||||
rb_hash_rehash(hash);
|
||||
}
|
||||
|
||||
if (FL_TEST(hash2, HASH_PROC_DEFAULT)) {
|
||||
FL_SET(hash, HASH_PROC_DEFAULT);
|
||||
}
|
||||
|
|
|
@ -100,6 +100,15 @@ class TestHash < Test::Unit::TestCase
|
|||
assert_raises(TypeError) { h.dup }
|
||||
end
|
||||
|
||||
def test_dup_will_rehash
|
||||
set1 = { }
|
||||
set2 = { set1 => true}
|
||||
|
||||
set1[set1] = true
|
||||
|
||||
assert_equal set2, set2.dup
|
||||
end
|
||||
|
||||
def test_s_AREF
|
||||
h = @cls["a" => 100, "b" => 200]
|
||||
assert_equal(100, h['a'])
|
||||
|
|
Loading…
Reference in a new issue