diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-09-11 15:50:46 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-09-14 19:20:55 +0000 |
commit | f44eb67f7dd922642a69834e18536c20e8218ba3 (patch) | |
tree | 9f95bc987741da451de1d163a8fd8e1041b2ce23 /src/qml/jsruntime/qv4identifiertable.cpp | |
parent | 6ed9a0817a5ab30e8f32aed0ecfa9c6c47071551 (diff) |
Improve performance of IdentifierTable::sweep()
Change-Id: I634f30ceb520af440c668e597a82b09b3c0024c9
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4identifiertable.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4identifiertable.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/src/qml/jsruntime/qv4identifiertable.cpp b/src/qml/jsruntime/qv4identifiertable.cpp index 14a580462f..e476baa886 100644 --- a/src/qml/jsruntime/qv4identifiertable.cpp +++ b/src/qml/jsruntime/qv4identifiertable.cpp @@ -90,7 +90,7 @@ void IdentifierTable::addEntry(Heap::StringOrSymbol *str) int newAlloc = primeForNumBits(numBits); Heap::StringOrSymbol **newEntries = (Heap::StringOrSymbol **)malloc(newAlloc*sizeof(Heap::String *)); memset(newEntries, 0, newAlloc*sizeof(Heap::StringOrSymbol *)); - for (int i = 0; i < alloc; ++i) { + for (uint i = 0; i < alloc; ++i) { Heap::StringOrSymbol *e = entriesByHash[i]; if (!e) continue; @@ -106,7 +106,7 @@ void IdentifierTable::addEntry(Heap::StringOrSymbol *str) newEntries = (Heap::StringOrSymbol **)malloc(newAlloc*sizeof(Heap::String *)); memset(newEntries, 0, newAlloc*sizeof(Heap::StringOrSymbol *)); - for (int i = 0; i < alloc; ++i) { + for (uint i = 0; i < alloc; ++i) { Heap::StringOrSymbol *e = entriesById[i]; if (!e) continue; @@ -252,39 +252,40 @@ void IdentifierTable::markObjects(MarkStack *markStack) h->markObjects(markStack); } -template <typename Key> -int sweepTable(Heap::StringOrSymbol **&table, int alloc, std::function<Key(Heap::StringOrSymbol *)> f) { +void IdentifierTable::sweep() +{ int freed = 0; Heap::StringOrSymbol **newTable = (Heap::StringOrSymbol **)malloc(alloc*sizeof(Heap::String *)); memset(newTable, 0, alloc*sizeof(Heap::StringOrSymbol *)); - for (int i = 0; i < alloc; ++i) { - Heap::StringOrSymbol *e = table[i]; + memset(entriesById, 0, alloc*sizeof(Heap::StringOrSymbol *)); + for (uint i = 0; i < alloc; ++i) { + Heap::StringOrSymbol *e = entriesByHash[i]; if (!e) continue; if (!e->isMarked()) { ++freed; continue; } - uint idx = f(e) % alloc; + uint idx = e->hashValue() % alloc; while (newTable[idx]) { ++idx; - idx %= alloc; + if (idx == alloc) + idx = 0; } newTable[idx] = e; - } - free(table); - table = newTable; - return freed; -} + idx = e->identifier.id() % alloc; + while (entriesById[idx]) { + ++idx; + if (idx == alloc) + idx = 0; + } + entriesById[idx] = e; + } + free(entriesByHash); + entriesByHash = newTable; -void IdentifierTable::sweep() -{ - int f = sweepTable<uint>(entriesByHash, alloc, [](Heap::StringOrSymbol *entry) {return entry->hashValue(); }); - int freed = sweepTable<quint64>(entriesById, alloc, [](Heap::StringOrSymbol *entry) {return entry->identifier.id(); }); - Q_UNUSED(f); - Q_ASSERT(f == freed); size -= freed; } |