From: Panu Matilainen Date: Sat, 15 Sep 2012 10:01:53 +0000 (+0300) Subject: Lift string pool rehash into a separate helper function X-Git-Tag: rpm-4.11.0-alpha~107 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=241fc3c143b90cccd47ceb5637542970ef470f25;p=platform%2Fupstream%2Frpm.git Lift string pool rehash into a separate helper function - This way we have exactly one place for controlling hash (re)creation size strategies etc. --- diff --git a/rpmio/rpmstrpool.c b/rpmio/rpmstrpool.c index bdec16b..9eaa107 100644 --- a/rpmio/rpmstrpool.c +++ b/rpmio/rpmstrpool.c @@ -29,10 +29,27 @@ struct rpmstrPool_s { 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; } @@ -82,13 +99,7 @@ void rpmstrPoolUnfreeze(rpmstrPool 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; } @@ -112,8 +123,7 @@ static rpmsid rpmstrPoolPut(rpmstrPool pool, const char *s, size_t slen, unsigne /* 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); } }