diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2012-09-17 15:01:46 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2012-09-17 15:14:08 +0300 |
commit | 533106ccfe4c459fb5a023fa2b1a41b8527d7fef (patch) | |
tree | afedc39edc39cb0adcb348c12d5bca831bb6c7eb /rpmio | |
parent | 38fe7e3b478d751610fcfc0c9bbe004a2633fd13 (diff) | |
download | librpm-tizen-533106ccfe4c459fb5a023fa2b1a41b8527d7fef.tar.gz librpm-tizen-533106ccfe4c459fb5a023fa2b1a41b8527d7fef.tar.bz2 librpm-tizen-533106ccfe4c459fb5a023fa2b1a41b8527d7fef.zip |
Eliminate key comparison and hash function vectors from poolHash
- As the pool is hardwired to single hash type, these dont make
any sense here and the extra indirection will only hurt performance.
Diffstat (limited to 'rpmio')
-rw-r--r-- | rpmio/rpmstrpool.c | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/rpmio/rpmstrpool.c b/rpmio/rpmstrpool.c index ae06d8be2..766993f67 100644 --- a/rpmio/rpmstrpool.c +++ b/rpmio/rpmstrpool.c @@ -12,8 +12,6 @@ static int pool_debug = 0; typedef struct poolHash_s * poolHash; -typedef unsigned int (*poolHashHashFunctionType) (const char * string); -typedef int (*poolHashHashEqualityType) (const char * key1, const char * key2); typedef struct poolHashBucket_s * poolHashBucket; struct poolHashBucket_s { @@ -25,8 +23,6 @@ struct poolHashBucket_s { struct poolHash_s { int numBuckets; poolHashBucket * buckets; - poolHashHashFunctionType fn; - poolHashHashEqualityType eq; int bucketCount; int keyCount; }; @@ -37,23 +33,19 @@ poolHashBucket poolHashfindEntry(poolHash ht, const char * key, unsigned int key unsigned int hash = keyHash % ht->numBuckets; poolHashBucket b = ht->buckets[hash]; - while (b && ht->eq(b->key, key)) + while (b && strcmp(b->key, key)) b = b->next; return b; } -static poolHash poolHashCreate(int numBuckets, - poolHashHashFunctionType fn, poolHashHashEqualityType eq) +static poolHash poolHashCreate(int numBuckets) { poolHash ht; ht = xmalloc(sizeof(*ht)); ht->numBuckets = numBuckets; ht->buckets = xcalloc(numBuckets, sizeof(*ht->buckets)); - - ht->fn = fn; - ht->eq = eq; ht->bucketCount = ht->keyCount = 0; return ht; } @@ -66,7 +58,7 @@ static void poolHashResize(poolHash ht, int numBuckets) poolHashBucket b = ht->buckets[i]; poolHashBucket nextB; while (b != NULL) { - unsigned int hash = ht->fn(b->key) % numBuckets; + unsigned int hash = rstrhash(b->key) % numBuckets; nextB = b->next; b->next = buckets[hash]; buckets[hash] = b; @@ -78,11 +70,6 @@ static void poolHashResize(poolHash ht, int numBuckets) ht->numBuckets = numBuckets; } -static unsigned int poolHashKeyHash(poolHash ht, const char * key) -{ - return ht->fn(key); -} - static void poolHashAddHEntry(poolHash ht, const char * key, unsigned int keyHash, rpmsid data) { unsigned int hash = keyHash % ht->numBuckets; @@ -92,7 +79,7 @@ static void poolHashAddHEntry(poolHash ht, const char * key, unsigned int keyHas ht->bucketCount += 1; } - while (b && ht->eq(b->key, key)) { + while (b && strcmp(b->key, key)) { b = b->next; } @@ -112,7 +99,7 @@ static void poolHashAddHEntry(poolHash ht, const char * key, unsigned int keyHas static void poolHashAddEntry(poolHash ht, const char * key, rpmsid data) { - poolHashAddHEntry(ht, key, ht->fn(key), data); + poolHashAddHEntry(ht, key, rstrhash(key), data); } static void poolHashEmpty( poolHash ht) @@ -202,7 +189,7 @@ static void rpmstrPoolRehash(rpmstrPool pool) if (pool->hash) pool->hash = poolHashFree(pool->hash); - pool->hash = poolHashCreate(sizehint, rstrhash, strcmp); + pool->hash = poolHashCreate(sizehint); for (int i = 1; i < pool->offs_size; i++) poolHashAddEntry(pool->hash, rpmstrPoolStr(pool, i), i); } @@ -311,7 +298,7 @@ rpmsid rpmstrPoolIdn(rpmstrPool pool, const char *s, size_t slen, int create) rpmsid sid = 0; if (pool && pool->hash && s) { - unsigned int hash = poolHashKeyHash(pool->hash, s); + unsigned int hash = rstrhash(s); sid = poolHashGetHEntry(pool->hash, s, hash); if (sid == 0 && create && !pool->frozen) { sid = rpmstrPoolPut(pool, s, slen, hash); |