diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-02-15 15:43:02 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-02-15 15:43:02 +0000 |
commit | 4ccf22e18d5e2c541ac195bf7e71af3abb5d82f7 (patch) | |
tree | 8535d9c9f4dcd3564d7d18e7911dd309395731d8 /hash.c | |
parent | bbf24e6d69a60ad691a00e55ed7ea9ae270d8620 (diff) |
merge revision(s) r42224,r42225,r42226,r42227,r42228,r42229,r42232: [Backport #8703]
* hash.c (rb_hash_assoc): performance improvement by replacing
compare function in RHASH(hash)->ntbl->type temporarily.
* hash.c (rb_hash_assoc): aggregate object can be initialized only
with link time constants.
* hash.c (rb_hash_initialize_copy): clear old table before copy new
table.
* hash.c (rb_hash_initialize_copy): copy st_table type even if empty.
[ruby-core:56256] [Bug #8703]
* hash.c (rb_hash_initialize_copy): copy st_table type even if empty.
[ruby-core:56256] [Bug #8703]
* hash.c (rb_hash_initialize_copy): clear old table before copy new
table.
* hash.c (rb_hash_assoc): aggregate object can be initialized only
with link time constants.
* hash.c (rb_hash_assoc): revert r42224. table->type->compare is
called only if hashes are matched.
* test/ruby/test_hash.rb: add a test to check using #== to compare.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@44979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -1223,14 +1223,22 @@ replace_i(VALUE key, VALUE val, VALUE hash) static VALUE rb_hash_initialize_copy(VALUE hash, VALUE hash2) { + st_table *ntbl; + rb_hash_modify_check(hash); hash2 = to_hash(hash2); Check_Type(hash2, T_HASH); - if (!RHASH_EMPTY_P(hash2)) { + ntbl = RHASH(hash)->ntbl; + if (RHASH(hash2)->ntbl) { + if (ntbl) st_free_table(ntbl); RHASH(hash)->ntbl = st_copy(RHASH(hash2)->ntbl); - rb_hash_rehash(hash); + if (RHASH(hash)->ntbl->num_entries) + rb_hash_rehash(hash); + } + else if (ntbl) { + st_clear(ntbl); } if (FL_TEST(hash2, HASH_PROC_DEFAULT)) { |