summaryrefslogtreecommitdiff
path: root/rpmio/rpmstrpool.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2012-09-12 19:29:28 +0300
committerPanu Matilainen <pmatilai@redhat.com>2012-09-12 19:29:28 +0300
commit2ea2a0961f380d844e4e1541df4f2c05f3b78449 (patch)
treee2288e92a6174ef17c58c0d25738379b370468ba /rpmio/rpmstrpool.c
parent86036abb978cb4bacc552446389e813554fdf2b0 (diff)
downloadlibrpm-tizen-2ea2a0961f380d844e4e1541df4f2c05f3b78449.tar.gz
librpm-tizen-2ea2a0961f380d844e4e1541df4f2c05f3b78449.tar.bz2
librpm-tizen-2ea2a0961f380d844e4e1541df4f2c05f3b78449.zip
Only rehash the pool on insert if the data area actually moved
- realloc() might not need to actually move the data, and when it doesn't we dont need to do the very expensive rehash either. Unsurprisingly makes things a whole lot faster.
Diffstat (limited to 'rpmio/rpmstrpool.c')
-rw-r--r--rpmio/rpmstrpool.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/rpmio/rpmstrpool.c b/rpmio/rpmstrpool.c
index 5792471d8..55fc0e0bd 100644
--- a/rpmio/rpmstrpool.c
+++ b/rpmio/rpmstrpool.c
@@ -100,6 +100,7 @@ static rpmsid rpmstrPoolPut(rpmstrPool pool, const char *s, size_t slen, unsigne
size_t ssize = slen + 1;
if (ssize > pool->data_alloced - pool->data_size) {
+ const char * prev_data = pool->data;
size_t need = pool->data_size + ssize;
size_t alloced = pool->data_alloced;
@@ -109,8 +110,8 @@ static rpmsid rpmstrPoolPut(rpmstrPool pool, const char *s, size_t slen, unsigne
pool->data = xrealloc(pool->data, alloced);
pool->data_alloced = alloced;
- /* ouch, need to rehash the whole lot as key addresses change */
- if (pool->offs_size > 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);
}