prevent Set "holes" from bloating memory
@@ -5357,11 +5357,19 @@ FIO_FUNC inline FIO_SET_TYPE FIO_NAME(_insert_or_overwrite_)(
/* locate future position, rehashing until a position is available */
FIO_NAME(_map_s_) *pos = FIO_NAME(_find_map_pos_)(set, hash_value, obj);
-
- while (!pos) {
+ if (!pos) {
+ /* no pos - so we know that we are inserting an object. */
+ /* Either we are over capacity, or we have too many holes in the map. */
+ if (set->pos >= set->capa) {
set->mask = (set->mask << 1) | 3;
FIO_NAME(rehash)(set);
- pos = FIO_NAME(_find_map_pos_)(set, hash_value, obj);
+ }
+ FIO_SET_COPY(set->ordered[set->pos].obj, obj);
+ set->ordered[set->pos].hash = hash_value;
+ ++set->pos;
+ ++set->count;
+ FIO_NAME(rehash)(set);
+ return set->ordered[set->pos - 1].obj;
}
/* overwriting / new */
@@ -5485,6 +5493,7 @@ FIO_FUNC inline int FIO_NAME(remove)(FIO_NAME(s) * set,
--set->count;
pos->pos->hash = FIO_SET_HASH_INVALID;
if (pos->pos == set->pos + set->ordered - 1) {
+ pos->hash = FIO_SET_HASH_INVALID; /* no need for a "hole" */
do {
--set->pos;
} while (set->pos && FIO_SET_HASH_COMPARE(set->ordered[set->pos - 1].hash,
