ruby-changes:23136
From: nobu <ko1@a...>
Date: Sat, 31 Mar 2012 07:53:35 +0900 (JST)
Subject: [ruby-changes:23136] nobu:r35186 (trunk): * st.c (st_foreach_check): remove the entry by replacing with never
nobu 2012-03-31 07:53:26 +0900 (Sat, 31 Mar 2012) New Revision: 35186 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35186 Log: * st.c (st_foreach_check): remove the entry by replacing with never when ST_DELETE. Modified files: trunk/ChangeLog trunk/hash.c trunk/st.c Index: ChangeLog =================================================================== --- ChangeLog (revision 35185) +++ ChangeLog (revision 35186) @@ -1,5 +1,8 @@ -Sat Mar 31 07:47:31 2012 Nobuyoshi Nakada <nobu@r...> +Sat Mar 31 07:53:23 2012 Nobuyoshi Nakada <nobu@r...> + * st.c (st_foreach_check): remove the entry by replacing with never + when ST_DELETE. + * hash.c (st_foreach_safe): since table is not for VALUE, Qundef is not special value, so use 0 instead. therefore this function can be applied to only st_table which 0 is invalid as keys, e.g., IDs. Index: st.c =================================================================== --- st.c (revision 35185) +++ st.c (revision 35186) @@ -130,6 +130,15 @@ } } +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 @@ 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 @@ 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 @@ 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; Index: hash.c =================================================================== --- hash.c (revision 35185) +++ hash.c (revision 35186) @@ -158,8 +158,8 @@ } switch (status) { case ST_DELETE: - st_delete_safe(tbl, &key, 0, (st_data_t)Qundef); FL_SET(arg->hash, HASH_DELETED); + return ST_DELETE; case ST_CONTINUE: break; case ST_STOP: -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/