aboutsummaryrefslogtreecommitdiffstats
path: root/qmljs_objects.h
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2012-11-28 13:44:26 +0100
committerLars Knoll <lars.knoll@digia.com>2012-11-28 14:07:09 +0100
commit803f57d53864582d694acb2a82d03393749d3b0c (patch)
tree3e45692633c55658f3c4161179e52f656041dbdf /qmljs_objects.h
parent721f2156a6c1ba77dd2c12bf06b7a3dcb0ea0b2c (diff)
Tune the bucket count a bit to be a prime upto 68000 entries.
The ECMA test suite has some tests that throw in vars with all possible unicode names. So, this should make it safer for longer. Change-Id: I4a65ab7d09a357d7665509d38e401098ab6e4607 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'qmljs_objects.h')
-rw-r--r--qmljs_objects.h25
1 files changed, 19 insertions, 6 deletions
diff --git a/qmljs_objects.h b/qmljs_objects.h
index 0b6f68992b..84dc513843 100644
--- a/qmljs_objects.h
+++ b/qmljs_objects.h
@@ -252,7 +252,9 @@ public:
, _freeList(0)
, _propertyCount(-1)
, _bucketCount(0)
- , _allocated(0) {}
+ , _primeIdx(-1)
+ , _allocated(0)
+ {}
~PropertyTable()
{
@@ -352,10 +354,7 @@ public:
private:
void rehash()
{
- if (_bucketCount)
- _bucketCount = _bucketCount * 2 + 1; // ### next prime
- else
- _bucketCount = 11;
+ _bucketCount = nextPrime();
delete[] _buckets;
_buckets = new PropertyTableEntry *[_bucketCount];
@@ -369,6 +368,19 @@ private:
}
}
+ inline int nextPrime()
+ {
+ // IMPORTANT: do not add more primes without checking if _primeIdx needs more bits!
+ static int primes[] = {
+ 11, 23, 47, 97, 197, 397, 797, 1597, 3203, 6421, 12853, 25717, 51437, 102877
+ };
+
+ if (_primeIdx < (int) (sizeof(primes)/sizeof(int)))
+ return primes[++_primeIdx];
+ else
+ return _bucketCount * 2 + 1; // Yes, we're degrading here. But who needs more than about 68000 properties?
+ }
+
private:
friend struct ForEachIteratorObject;
PropertyTableEntry **_properties;
@@ -376,7 +388,8 @@ private:
PropertyTableEntry *_freeList;
int _propertyCount;
int _bucketCount;
- int _allocated;
+ int _primeIdx: 4;
+ int _allocated: 28;
};
struct Object {