int nrefs; /* refcount */
};
+static void rpmstrPoolRehash(rpmstrPool pool)
+{
+ int sizehint;
+
+ if (pool->offs_size < STRHASH_INITSIZE)
+ sizehint = STRHASH_INITSIZE;
+ else
+ sizehint = pool->offs_size * 2;
+
+ if (pool->hash)
+ pool->hash = strHashFree(pool->hash);
+
+ pool->hash = strHashCreate(sizehint, rstrhash, strcmp, NULL, NULL);
+ for (int i = 1; i < pool->offs_size; i++)
+ strHashAddEntry(pool->hash, rpmstrPoolStr(pool, i), i);
+}
+
rpmstrPool rpmstrPoolCreate(void)
{
rpmstrPool pool = xcalloc(1, sizeof(*pool));
- pool->hash = strHashCreate(STRHASH_INITSIZE, rstrhash, strcmp, NULL, NULL);
+ rpmstrPoolRehash(pool);
pool->nrefs = 1;
return pool;
}
{
if (pool) {
if (pool->hash == NULL) {
- int sizehint = pool->offs_size * 2;
- if (sizehint < STRHASH_INITSIZE)
- sizehint = STRHASH_INITSIZE;
- pool->hash = strHashCreate(sizehint, rstrhash, strcmp, NULL, NULL);
- for (int i = 1; i < pool->offs_size; i++) {
- strHashAddEntry(pool->hash, rpmstrPoolStr(pool, i), i);
- }
+ rpmstrPoolRehash(pool);
}
pool->frozen = 0;
}
/* ouch, need to rehash the whole lot if key addresses change */
if (pool->offs_size > 0 && pool->data != prev_data) {
- pool->hash = strHashFree(pool->hash);
- rpmstrPoolUnfreeze(pool);
+ rpmstrPoolRehash(pool);
}
}