diff --git a/ChangeLog b/ChangeLog index 52612dc35b..8dd7490092 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Thu Jan 27 23:29:36 2011 Nobuyoshi Nakada + + * st.c (st_foreach): check if unpacked. + Thu Jan 27 23:14:19 2011 Nobuyoshi Nakada * misc/ruby-mode.el (ruby-mode-map): remove deprecated binding. diff --git a/st.c b/st.c index a076280c31..ba21b31a5b 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);