summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXavier Roche <xroche@users.noreply.github.com>2013-07-14 07:33:43 +0000
committerXavier Roche <xroche@users.noreply.github.com>2013-07-14 07:33:43 +0000
commit4c6c2fa349f39bb374cba096739f39e1edceacc6 (patch)
treedd5cf41e33280c9dbbfb3c4430e369521d73d440 /src
parent1ed1ddf658370994ece99f904b386256374ab2d1 (diff)
Really compact when needed the string pool
Diffstat (limited to 'src')
-rw-r--r--src/htsinthash.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/htsinthash.c b/src/htsinthash.c
index 6cba621..5777435 100644
--- a/src/htsinthash.c
+++ b/src/htsinthash.c
@@ -357,7 +357,7 @@ static HTS_INLINE int inthash_matches(inthash hashtable, size_t pos,
static void inthash_compact_pool(inthash hashtable, size_t capacity) {
const size_t hash_size = POW2(hashtable->lg_size);
size_t i;
- char* old_pool = hashtable->pool.buffer;
+ char*const old_pool = hashtable->pool.buffer;
const size_t old_size = hashtable->pool.size;
size_t count = 0;
@@ -396,6 +396,7 @@ static void inthash_compact_pool(inthash hashtable, size_t capacity) {
inthash_assert(j < capacity); \
dest[j] = src[i]; \
} \
+ inthash_assert(j < capacity); \
dest[j++] = '\0'; \
hashtable->pool.size = j; \
count++; \
@@ -515,7 +516,11 @@ static void inthash_free_key_internal(inthash hashtable, char *name) {
const size_t len = strlen(name) + 1;
hashtable->pool.used -= len;
if (hashtable->pool.used < hashtable->pool.size / 2) {
- inthash_compact_pool(hashtable, hashtable->pool.capacity);
+ size_t capacity = hashtable->pool.capacity;
+ if (hashtable->pool.used < capacity / 4) {
+ capacity /= 2;
+ }
+ inthash_compact_pool(hashtable, capacity);
}
}