summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-27 14:30:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-27 14:30:00 +0000
commit4a42b101a9521b74ded79f2dc1b6260533abca8c (patch)
treefaafce5231efbe0799c40acafc869bd3eb95dedb /st.c
parentc5b45d252a24b10d2bf00b88f5b1180c8df986c0 (diff)
* st.c (st_foreach): check if unpacked.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'st.c')
-rw-r--r--st.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/st.c b/st.c
index a076280..ba21b31 100644
--- a/st.c
+++ b/st.c
@@ -745,6 +745,7 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
key = (st_data_t)table->bins[i*2];
val = (st_data_t)table->bins[i*2+1];
retval = (*func)(key, val, arg);
+ if (!table->entries_packed) goto unpacked;
switch (retval) {
case ST_CHECK: /* check if hash is modified during iteration */
for (j = 0; j < table->num_entries; j++) {
@@ -770,9 +771,17 @@ st_foreach(st_table *table, int (*func)(ANYARGS), st_data_t arg)
}
}
return 0;
+ unpacked:
+ ptr = table->head;
+ while (i-- > 0) {
+ if (!(ptr = ptr->fore)) return 0;
+ }
+ }
+ else {
+ ptr = table->head;
}
- if ((ptr = table->head) != 0) {
+ if (ptr != 0) {
do {
i = ptr->hash % table->num_bins;
retval = (*func)(ptr->key, ptr->record, arg);