Avoid rehashing in Hash#replace/dup/initialize_copy [Bug #16996]
This commit is contained in:
parent
d094c3ef04
commit
0ef2923c2b
2
hash.c
2
hash.c
@ -2958,7 +2958,7 @@ rb_hash_replace(VALUE hash, VALUE hash2)
|
|||||||
RHASH_TBL_RAW(hash)->type = RHASH_ST_TABLE(hash2)->type;
|
RHASH_TBL_RAW(hash)->type = RHASH_ST_TABLE(hash2)->type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rb_hash_foreach(hash2, rb_hash_rehash_i, (VALUE)hash);
|
hash_copy(hash, hash2);
|
||||||
|
|
||||||
rb_gc_writebarrier_remember(hash);
|
rb_gc_writebarrier_remember(hash);
|
||||||
|
|
||||||
|
@ -113,13 +113,8 @@ class TestHash < Test::Unit::TestCase
|
|||||||
assert_equal(2, h[1])
|
assert_equal(2, h[1])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dup_will_rehash
|
def test_dup_will_not_rehash
|
||||||
set1 = @cls[]
|
assert_hash_does_not_rehash(&:dup)
|
||||||
set2 = @cls[set1 => true]
|
|
||||||
|
|
||||||
set1[set1] = true
|
|
||||||
|
|
||||||
assert_equal set2, set2.dup
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_hash_does_not_rehash
|
def assert_hash_does_not_rehash
|
||||||
@ -480,6 +475,7 @@ class TestHash < Test::Unit::TestCase
|
|||||||
h1 = @cls[h => 1]
|
h1 = @cls[h => 1]
|
||||||
assert_equal(h1, h1.dup)
|
assert_equal(h1, h1.dup)
|
||||||
h[1] = 2
|
h[1] = 2
|
||||||
|
h1.rehash
|
||||||
assert_equal(h1, h1.dup)
|
assert_equal(h1, h1.dup)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -637,11 +637,10 @@ class TC_Set < Test::Unit::TestCase
|
|||||||
assert_not_equal(Set[1], [1])
|
assert_not_equal(Set[1], [1])
|
||||||
|
|
||||||
set1 = Class.new(Set)["a", "b"]
|
set1 = Class.new(Set)["a", "b"]
|
||||||
set2 = Set["a", "b", set1]
|
set1.add(set1).reset # Make recursive
|
||||||
set1 = set1.add(set1.clone)
|
set2 = Set["a", "b", Set["a", "b", set1]]
|
||||||
|
|
||||||
assert_equal(set2, set2.clone)
|
assert_equal(set1, set2)
|
||||||
assert_equal(set1.clone, set1)
|
|
||||||
|
|
||||||
assert_not_equal(Set[Exception.new,nil], Set[Exception.new,Exception.new], "[ruby-dev:26127]")
|
assert_not_equal(Set[Exception.new,nil], Set[Exception.new,Exception.new], "[ruby-dev:26127]")
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user