diff options
Diffstat (limited to 'src/qml/jsruntime/qv4identifiertable.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4identifiertable.cpp | 52 |
1 files changed, 15 insertions, 37 deletions
diff --git a/src/qml/jsruntime/qv4identifiertable.cpp b/src/qml/jsruntime/qv4identifiertable.cpp index 0412695404..14a580462f 100644 --- a/src/qml/jsruntime/qv4identifiertable.cpp +++ b/src/qml/jsruntime/qv4identifiertable.cpp @@ -253,51 +253,29 @@ void IdentifierTable::markObjects(MarkStack *markStack) } template <typename Key> -int sweepTable(Heap::StringOrSymbol **table, int alloc, std::function<Key(Heap::StringOrSymbol *)> f) { +int sweepTable(Heap::StringOrSymbol **&table, int alloc, std::function<Key(Heap::StringOrSymbol *)> f) { int freed = 0; - uint lastKey = 0; - - int lastEntry = -1; - int start = 0; - // start at an empty entry so we compress properly - for (; start < alloc; ++start) { - if (!table[start]) - break; - } + Heap::StringOrSymbol **newTable = (Heap::StringOrSymbol **)malloc(alloc*sizeof(Heap::String *)); + memset(newTable, 0, alloc*sizeof(Heap::StringOrSymbol *)); for (int i = 0; i < alloc; ++i) { - int idx = (i + start) % alloc; - Heap::StringOrSymbol *entry = table[idx]; - if (!entry) { - lastEntry = -1; + Heap::StringOrSymbol *e = table[i]; + if (!e) continue; - } - if (entry->isMarked()) { - if (lastEntry >= 0 && lastKey == (f(entry) % alloc)) { - Q_ASSERT(table[lastEntry] == nullptr); - table[lastEntry] = entry; - table[idx] = nullptr; - - // find next free slot just like in addEntry() - do { - lastEntry = (lastEntry + 1) % alloc; - } while (table[lastEntry] != nullptr); - } + if (!e->isMarked()) { + ++freed; continue; } - if (lastEntry == -1) { - lastEntry = idx; - lastKey = f(entry) % alloc; + uint idx = f(e) % alloc; + while (newTable[idx]) { + ++idx; + idx %= alloc; } - table[idx] = nullptr; - ++freed; - } - for (int i = 0; i < alloc; ++i) { - Heap::StringOrSymbol *entry = table[i]; - if (!entry) - continue; - Q_ASSERT(entry->isMarked()); + newTable[idx] = e; } + free(table); + table = newTable; + return freed; } |