From 700433fc16e14292880ec9d329699e1cd889367e Mon Sep 17 00:00:00 2001 From: Roberto Raggi <roberto.raggi@nokia.com> Date: Wed, 1 Sep 2010 14:10:25 +0200 Subject: [PATCH] Tune the default size of literal tables. This simple change will save about 40mb of memory when indexing Qt Creator! --- src/shared/cplusplus/LiteralTable.h | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/shared/cplusplus/LiteralTable.h b/src/shared/cplusplus/LiteralTable.h index 5a9a1f878bd..80ada26e51a 100644 --- a/src/shared/cplusplus/LiteralTable.h +++ b/src/shared/cplusplus/LiteralTable.h @@ -66,9 +66,9 @@ public: public: LiteralTable() : _literals(0), + _buckets(0), _allocatedLiterals(0), _literalCount(-1), - _buckets(0), _allocatedBuckets(0) { } @@ -127,17 +127,13 @@ public: _Literal *literal = new _Literal(chars, size); if (++_literalCount == _allocatedLiterals) { - _allocatedLiterals <<= 1; - - if (! _allocatedLiterals) - _allocatedLiterals = 256; - + _allocatedLiterals += 32; _literals = (_Literal **) std::realloc(_literals, sizeof(_Literal *) * _allocatedLiterals); } _literals[_literalCount] = literal; - if (! _buckets || _literalCount >= _allocatedBuckets * .6) + if (! _buckets || _literalCount * 5 >= _allocatedBuckets * 3) rehash(); else { unsigned h = literal->hashCode() % _allocatedBuckets; @@ -154,11 +150,7 @@ protected: if (_buckets) std::free(_buckets); - _allocatedBuckets <<= 1; - - if (! _allocatedBuckets) - _allocatedBuckets = 256; - + _allocatedBuckets += 32; _buckets = (_Literal **) std::calloc(_allocatedBuckets, sizeof(_Literal *)); _Literal **lastLiteral = _literals + (_literalCount + 1); @@ -174,10 +166,9 @@ protected: protected: _Literal **_literals; + _Literal **_buckets; int _allocatedLiterals; int _literalCount; - - _Literal **_buckets; int _allocatedBuckets; }; -- GitLab