From cf1a22fdf914f96126f5a8b671dab9a69db236f8 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 7 Feb 2012 05:52:15 +0000 Subject: * st.c (st_update): table can be unpacked in the callback. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- st.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'st.c') diff --git a/st.c b/st.c index 215e27b298..c45338abfd 100644 --- a/st.c +++ b/st.c @@ -761,12 +761,21 @@ st_update(st_table *table, st_data_t key, int (*func)(st_data_t key, st_data_t * st_index_t hash_val, bin_pos; register st_table_entry *ptr, **last, *tmp; st_data_t value; + int retval; if (table->entries_packed) { st_index_t i = find_packed_index(table, key); if (i < table->num_entries) { value = PVAL(table, i); - switch ((*func)(key, &value, arg)) { + retval = (*func)(key, &value, arg); + if (!table->entries_packed) { + hash_val = do_hash(key, table); + bin_pos = hash_val % table->num_bins; + ptr = find_entry(table, key, hash_val, bin_pos); + if (ptr == 0) return 0; + goto unpacked; + } + switch (retval) { case ST_CONTINUE: PVAL_SET(table, i, value); break; @@ -787,7 +796,9 @@ st_update(st_table *table, st_data_t key, int (*func)(st_data_t key, st_data_t * } else { value = ptr->record; - switch ((*func)(ptr->key, &value, arg)) { + retval = (*func)(ptr->key, &value, arg); + unpacked: + switch (retval) { case ST_CONTINUE: ptr->record = value; break; -- cgit v1.2.3