]> git.ozlabs.org Git - ccan/blobdiff - ccan/htable/htable.c
htable: opportunistically avoid delete marker.
[ccan] / ccan / htable / htable.c
index c5f166f83e3fc0f188f9907a6a6da55f0e60cb5a..f631ffebf1f7540416a050c800bcf5cd42268470 100644 (file)
@@ -418,8 +418,12 @@ void htable_delval_(struct htable *ht, struct htable_iter *i)
        assert(entry_is_valid(ht->table[i->off]));
 
        ht->elems--;
-       ht->table[i->off] = HTABLE_DELETED;
-       ht->deleted++;
+       /* Cheap test: if the next bucket is empty, don't need delete marker */
+       if (ht->table[hash_bucket(ht, i->off+1)] != 0) {
+               ht->table[i->off] = HTABLE_DELETED;
+               ht->deleted++;
+       } else
+               ht->table[i->off] = 0;
 }
 
 void *htable_pick_(const struct htable *ht, size_t seed, struct htable_iter *i)