From 33357d4f35810a0fd182241cc96d27a69c0a3044 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 20 Nov 2024 10:41:19 +0900 Subject: [PATCH] hash.c (ht_set_without_ib_adjustment): need to skip tombstone; #6421 If a tombstone (a deleted entry slot) is found in searching the entry, it should be skipped, but we had added the new entry even if the entry to be replaced might be found in the further search. #6414 and #6421 tried to rehash the table to remove tombstone. But rehashing consumes memory. So for the time being, we just skip tombstones in the search. Maybe we will add some heuristics to rehash when the table has too many tombstones. close #6414 --- src/hash.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/hash.c b/src/hash.c index 95d1bcd3b..3e2af87ec 100644 --- a/src/hash.c +++ b/src/hash.c @@ -295,8 +295,7 @@ static void ht_init( mrb_state *mrb, struct RHash *h, uint32_t size, hash_entry *ea, uint32_t ea_capa, hash_table *ht, uint32_t ib_bit); static void ht_set(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value val); -static void ht_set_without_ib_adjustment( - mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value val); +static void ht_set_without_ib_adjustment(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value val); static uint32_t next_power2(uint32_t v) @@ -847,8 +846,7 @@ ht_set_as_ar(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value val) } static void -ht_set_without_ib_adjustment(mrb_state *mrb, struct RHash *h, - mrb_value key, mrb_value val) +ht_set_without_ib_adjustment(mrb_state *mrb, struct RHash *h, mrb_value key, mrb_value val) { mrb_assert(ht_size(h) < ib_bit_to_capa(ib_bit(h))); ib_cycle_by_key(mrb, h, key, it, { @@ -856,6 +854,9 @@ ht_set_without_ib_adjustment(mrb_state *mrb, struct RHash *h, if (!obj_eql(mrb, key, ib_it_entry(it)->key, h)) continue; ib_it_entry(it)->val = val; } + else if (ib_it_deleted_p(it)) { + continue; + } else { uint32_t ea_n_used = ht_ea_n_used(h); if (ea_n_used == H_MAX_SIZE) {