diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2012-09-15 13:01:53 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2012-09-15 13:01:53 +0300 |
commit | 241fc3c143b90cccd47ceb5637542970ef470f25 (patch) | |
tree | f69f536d8fccc9e9813753aead884f1717d6766e /rpmio | |
parent | 95329e10bee61848428c12e971fb9749a1285b55 (diff) | |
download | librpm-tizen-241fc3c143b90cccd47ceb5637542970ef470f25.tar.gz librpm-tizen-241fc3c143b90cccd47ceb5637542970ef470f25.tar.bz2 librpm-tizen-241fc3c143b90cccd47ceb5637542970ef470f25.zip |
Lift string pool rehash into a separate helper function
- This way we have exactly one place for controlling hash (re)creation
size strategies etc.
Diffstat (limited to 'rpmio')
-rw-r--r-- | rpmio/rpmstrpool.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/rpmio/rpmstrpool.c b/rpmio/rpmstrpool.c index bdec16bce..9eaa107fe 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); } } |