diff options
author | Xavier Roche <xroche@users.noreply.github.com> | 2014-06-28 11:18:06 +0000 |
---|---|---|
committer | Xavier Roche <xroche@users.noreply.github.com> | 2014-06-28 11:18:06 +0000 |
commit | 5eb5b0891db2d2726badcdbf283674153a1a0a20 (patch) | |
tree | 5f8c285f2b926860a7d7de842e795808a70eeb7d | |
parent | afff7dc03340f6714f61e497efc23354d5b1c652 (diff) |
Optimize the case when realloc() returns the same base address while reallocating the string pool.
-rw-r--r-- | src/coucal.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/coucal.c b/src/coucal.c index 663bfc8..8b5f404 100644 --- a/src/coucal.c +++ b/src/coucal.c @@ -510,7 +510,7 @@ static INTHASH_INLINE int coucal_matches(coucal hashtable, size_t pos, return coucal_matches_(hashtable, item, name, hashes); } -/* compact string pool ; does not change the capacity */ +/* compact string pool ; does not necessarily change the capacity */ static void coucal_compact_pool(coucal hashtable, size_t capacity) { const size_t hash_size = POW2(hashtable->lg_size); size_t i; @@ -597,7 +597,6 @@ static void coucal_compact_pool(coucal hashtable, size_t capacity) { static void coucal_realloc_pool(coucal hashtable, size_t capacity) { const size_t hash_size = POW2(hashtable->lg_size); char *const oldbase = hashtable->pool.buffer; - size_t i; size_t count = 0; /* we manage the string pool */ @@ -636,12 +635,15 @@ static void coucal_realloc_pool(coucal hashtable, size_t capacity) { } \ } while(0) - /* recompute */ - for(i = 0 ; i < hash_size ; i++) { - RECOMPUTE_STRING(hashtable->items[i].name); - } - for(i = 0 ; i < hashtable->stash.size ; i++) { - RECOMPUTE_STRING(hashtable->stash.items[i].name); + /* recompute string addresses */ + if (hashtable->pool.buffer != oldbase) { + size_t i; + for(i = 0 ; i < hash_size ; i++) { + RECOMPUTE_STRING(hashtable->items[i].name); + } + for(i = 0 ; i < hashtable->stash.size ; i++) { + RECOMPUTE_STRING(hashtable->stash.items[i].name); + } } #undef RECOMPUTE_STRING |