diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-30 22:53:26 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-30 22:53:26 +0000 |
commit | 197627354e3c065542d92f5541425df699f4b204 (patch) | |
tree | 12e37a2ef3bfcd64323a4f2a1acc8a093cdeb22c /st.c | |
parent | d0380e2e567d9ffa1423c8b6fda3470f11b753c3 (diff) |
* st.c (st_foreach_check): remove the entry by replacing with never
when ST_DELETE.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'st.c')
-rw-r--r-- | st.c | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -130,6 +130,15 @@ remove_packed_entry(st_table *table, st_index_t i) } } +static inline void +remove_safe_packed_entry(st_table *table, st_index_t i, st_data_t never) +{ + table->num_entries--; + PKEY_SET(table, i, never); + PVAL_SET(table, i, never); + PHASH_SET(table, i, 0); +} + /* * MINSIZE is the minimum size of a dictionary. */ @@ -761,10 +770,7 @@ st_delete_safe(register st_table *table, register st_data_t *key, st_data_t *val if (i < table->real_entries) { if (value != 0) *value = PVAL(table, i); *key = PKEY(table, i); - PKEY_SET(table, i, never); - PVAL_SET(table, i, never); - PHASH_SET(table, i, 0); - table->num_entries--; + remove_safe_packed_entry(table, i, never); return 1; } if (value != 0) *value = 0; @@ -936,8 +942,7 @@ st_foreach_check(st_table *table, int (*func)(ANYARGS), st_data_t arg, st_data_t case ST_STOP: return 0; case ST_DELETE: - remove_packed_entry(table, i); - i--; + remove_safe_packed_entry(table, i, never); break; } } @@ -976,9 +981,9 @@ st_foreach_check(st_table *table, int (*func)(ANYARGS), st_data_t arg, st_data_t for (; (tmp = *last) != 0; last = &tmp->next) { if (ptr == tmp) { tmp = ptr->fore; - *last = ptr->next; remove_entry(table, ptr); - st_free_entry(ptr); + ptr->key = ptr->record = never; + ptr->hash = 0; if (ptr == tmp) return 0; ptr = tmp; break; |