diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-29 07:51:23 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-29 07:51:23 +0000 |
commit | be24b385ffb2c31e5f0974aee55bce1e37f1bc2b (patch) | |
tree | 8ab725e28efaeb91cdf7f216dce8e6ac62907dce /hash.c | |
parent | ac82a1b2058a0f5049bf77895003cbf0ba092f4c (diff) | |
download | ruby-be24b385ffb2c31e5f0974aee55bce1e37f1bc2b.tar.gz |
ChangeLog: commit miss
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -1306,14 +1306,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)) { @@ -2167,11 +2175,10 @@ rb_hash_assoc(VALUE hash, VALUE key) struct lookup2_arg arg; struct reset_hash_type_arg ensure_arg; const struct st_hash_type *orighash = table->type; - const struct st_hash_type assochash = { - assoc_cmp, - orighash->hash, - }; + struct st_hash_type assochash; + assochash.compare = assoc_cmp; + assochash.hash = orighash->hash; table->type = &assochash; arg.hash = hash; arg.key = key; |