hash.c: remove special treatments on deletion

st.c was improved in r56650 that it permits deletion during iteration.
In this commit, special treatments for previous implementation are
removed.

* hash.c: don't use *_check and *_safe functions in st.c

* internal.h: remove HASH_DELETED flag

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
glass 2017-09-30 11:58:33 +00:00
Родитель e7c8073a62
Коммит c879b60152
2 изменённых файлов: 3 добавлений и 15 удалений

17
hash.c
Просмотреть файл

@ -348,7 +348,6 @@ hash_foreach_iter(st_data_t key, st_data_t value, st_data_t argp, int error)
}
switch (status) {
case ST_DELETE:
FL_SET(arg->hash, HASH_DELETED);
return ST_DELETE;
case ST_CONTINUE:
break;
@ -368,12 +367,7 @@ hash_foreach_ensure_rollback(VALUE hash)
static VALUE
hash_foreach_ensure(VALUE hash)
{
if (--RHASH_ITER_LEV(hash) == 0) {
if (FL_TEST(hash, HASH_DELETED)) {
st_cleanup_safe(RHASH(hash)->ntbl, (st_data_t)Qundef);
FL_UNSET(hash, HASH_DELETED);
}
}
RHASH_ITER_LEV(hash)--;
return 0;
}
@ -1108,11 +1102,6 @@ rb_hash_delete_entry(VALUE hash, VALUE key)
if (!RHASH(hash)->ntbl) {
return Qundef;
}
else if (RHASH_ITER_LEV(hash) > 0 &&
(st_delete_safe(RHASH(hash)->ntbl, &ktmp, &val, (st_data_t)Qundef))) {
FL_SET(hash, HASH_DELETED);
return (VALUE)val;
}
else if (st_delete(RHASH(hash)->ntbl, &ktmp, &val)) {
return (VALUE)val;
}
@ -2120,7 +2109,7 @@ rb_hash_keys(VALUE hash)
rb_gc_writebarrier_remember(keys);
RARRAY_PTR_USE(keys, ptr, {
size = st_keys_check(table, ptr, size, Qundef);
size = st_keys(table, ptr, size);
});
rb_ary_set_len(keys, size);
}
@ -2164,7 +2153,7 @@ rb_hash_values(VALUE hash)
rb_gc_writebarrier_remember(values);
RARRAY_PTR_USE(values, ptr, {
size = st_values_check(table, ptr, size, Qundef);
size = st_values(table, ptr, size);
});
rb_ary_set_len(values, size);
}

Просмотреть файл

@ -1259,7 +1259,6 @@ VALUE rb_hash_keys(VALUE hash);
VALUE rb_hash_values(VALUE hash);
VALUE rb_hash_rehash(VALUE hash);
int rb_hash_add_new_element(VALUE hash, VALUE key, VALUE val);
#define HASH_DELETED FL_USER1
#define HASH_PROC_DEFAULT FL_USER2
/* inits.c */