| 124 | } |
| 125 | |
| 126 | void *cbm_ht_set(CBMHashTable *ht, const char *key, void *value) { |
| 127 | if (!ht || !key) |
| 128 | return NULL; |
| 129 | /* ONE probe: get_or_insert either inserts (key, value) or hands back the |
| 130 | * existing entry, whose previous value is returned and whose key AND value |
| 131 | * are replaced -- exactly what _insert did. The old get-then-insert hashed |
| 132 | * every key twice: 83 M repeated strlen calls inside vt_hash_string on the |
| 133 | * Go corpus (waste sanitizer, 2026-09-17). Verstable reports an insertion |
| 134 | * as a size change. */ |
| 135 | void *prev = NULL; |
| 136 | HT_WROTE(ht); |
| 137 | #if defined(CBM_MEMWASTE) && CBM_MEMWASTE |
| 138 | size_t buckets_before = cbm_vt_bucket_count(&ht->vt); |
| 139 | #endif |
| 140 | size_t size_before = cbm_vt_size(&ht->vt); |
| 141 | cbm_vt_itr itr = cbm_vt_get_or_insert(&ht->vt, key, value); |
| 142 | if (!cbm_vt_is_end(itr) && cbm_vt_size(&ht->vt) == size_before) { |
| 143 | prev = itr.data->val; |
| 144 | itr.data->key = key; |
| 145 | itr.data->val = value; |
| 146 | } |
| 147 | #if defined(CBM_MEMWASTE) && CBM_MEMWASTE |
| 148 | bool grew = cbm_vt_bucket_count(&ht->vt) != buckets_before; |
| 149 | if (grew) { |
| 150 | ht->waste_growths++; |
| 151 | } |
| 152 | if (cbm_memev_enabled()) { |
| 153 | cbm_work_note(CBM_WORK_HT_SET, ht->waste_site, 0, grew ? 1 : 0, 0); |
| 154 | } |
| 155 | #endif |
| 156 | return prev; |
| 157 | } |
| 158 | |
| 159 | void *cbm_ht_get(const CBMHashTable *ht, const char *key) { |
| 160 | if (!ht || !key) |