aboutsummaryrefslogtreecommitdiffstats
path: root/st.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-07 05:52:15 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-07 05:52:15 +0000
commitcf1a22fdf914f96126f5a8b671dab9a69db236f8 (patch)
treef29f4544c0b908746734dc336209fe13c7850d89 /st.c
parentaf01b0fb07af13238cf4a881853d3f8c8787649e (diff)
downloadruby-cf1a22fdf914f96126f5a8b671dab9a69db236f8.tar.gz
* 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
Diffstat (limited to 'st.c')
-rw-r--r--st.c15
1 files changed, 13 insertions, 2 deletions
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;