summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/hash.c b/hash.c
index 48c0aba..102682c 100644
--- a/hash.c
+++ b/hash.c
@@ -460,12 +460,12 @@ rb_hash_shift(hash)
}
static enum st_retval
-delete_if_i(key, value, keys)
- VALUE key, value, keys;
+delete_if_i(key, value)
+ VALUE key, value;
{
- if (key != Qundef && RTEST(rb_yield_values(2, key, value))) {
- rb_ary_push(keys, key);
- }
+ if (key == Qundef) return ST_CONTINUE;
+ if (RTEST(rb_yield_values(2, key, value)))
+ return ST_DELETE;
return ST_CONTINUE;
}
@@ -473,14 +473,8 @@ VALUE
rb_hash_delete_if(hash)
VALUE hash;
{
- VALUE keys = rb_ary_new();
- long i;
-
rb_hash_modify(hash);
- rb_hash_foreach(hash, delete_if_i, keys);
- for (i=0; i<RARRAY(keys)->len; i++) {
- st_delete(RHASH(hash)->tbl, &RARRAY(keys)->ptr[i], 0);
- }
+ rb_hash_foreach(hash, delete_if_i, 0);
return hash;
}