aboutsummaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-22 09:52:35 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-22 09:52:35 +0000
commit0e2ab7ea3c308078e71263b0ba83259e1a238fa7 (patch)
treeb5a33c5aaa64a868950a8ffc5de72586374628da /hash.c
parent5b9f5d54ddb8848ecb62b979112b644280d29fee (diff)
downloadruby-0e2ab7ea3c308078e71263b0ba83259e1a238fa7.tar.gz
hash.c: fix Hash#compact! return value
* hash.c (rb_hash_compact_bang): should return nil if no elements is deleted. [ruby-core:77709] [Bug #12863] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/hash.c b/hash.c
index 630269d125..db8bdc8bb6 100644
--- a/hash.c
+++ b/hash.c
@@ -2726,9 +2726,12 @@ rb_hash_compact_bang(VALUE hash)
{
rb_hash_modify_check(hash);
if (RHASH(hash)->ntbl) {
+ st_index_t n = RHASH(hash)->ntbl->num_entries;
rb_hash_foreach(hash, delete_if_nil, hash);
+ if (n != RHASH(hash)->ntbl->num_entries)
+ return hash;
}
- return hash;
+ return Qnil;
}
static VALUE rb_hash_compare_by_id_p(VALUE hash);