diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-04-06 13:41:29 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-05-02 14:18:06 +0000 |
commit | b58711804e9cca641927dbdebe281488e475352b (patch) | |
tree | cb7671cb6edc52e5e744a370704ec068c7ab45eb /src/qml/jsruntime/qv4identifiertable.cpp | |
parent | 238b1cb1cb8915995b6dfe4e404f1771c62b3169 (diff) |
Use Identifier by value and don't new them anymore
Change-Id: Ib25c08027013217657beb2675dafa9a8c85cbaf9
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4identifiertable.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4identifiertable.cpp | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/qml/jsruntime/qv4identifiertable.cpp b/src/qml/jsruntime/qv4identifiertable.cpp index cd5a7ebc3e..2cfdd81c87 100644 --- a/src/qml/jsruntime/qv4identifiertable.cpp +++ b/src/qml/jsruntime/qv4identifiertable.cpp @@ -67,9 +67,6 @@ IdentifierTable::IdentifierTable(ExecutionEngine *engine) IdentifierTable::~IdentifierTable() { - for (int i = 0; i < alloc; ++i) - if (entriesByHash[i]) - delete entriesByHash[i]->identifier; free(entriesByHash); free(entriesById); } @@ -81,8 +78,7 @@ void IdentifierTable::addEntry(Heap::String *str) if (str->subtype == Heap::String::StringType_ArrayIndex) return; - str->identifier = new Identifier; - str->identifier->id = engine->nextStringOrSymbolId(); + str->identifier = engine->nextIdentifier(); bool grow = (alloc <= size*2); @@ -111,7 +107,7 @@ void IdentifierTable::addEntry(Heap::String *str) Heap::String *e = entriesById[i]; if (!e) continue; - uint idx = e->identifier->id % newAlloc; + uint idx = e->identifier.id % newAlloc; while (newEntries[idx]) { ++idx; idx %= newAlloc; @@ -131,7 +127,7 @@ void IdentifierTable::addEntry(Heap::String *str) } entriesByHash[idx] = str; - idx = str->identifier->id % alloc; + idx = str->identifier.id % alloc; while (entriesById[idx]) { ++idx; idx %= alloc; @@ -163,13 +159,13 @@ Heap::String *IdentifierTable::insertString(const QString &s) } -Identifier *IdentifierTable::identifierImpl(const Heap::String *str) +Identifier IdentifierTable::identifierImpl(const Heap::String *str) { - if (str->identifier) + if (str->identifier.isValid()) return str->identifier; uint hash = str->hashValue(); if (str->subtype == Heap::String::StringType_ArrayIndex) - return nullptr; + return Identifier::invalid(); uint idx = hash % alloc; while (Heap::String *e = entriesByHash[idx]) { @@ -185,12 +181,12 @@ Identifier *IdentifierTable::identifierImpl(const Heap::String *str) return str->identifier; } -Heap::String *IdentifierTable::stringFromIdentifier(const Identifier *i) const +Heap::String *IdentifierTable::stringForId(Identifier i) const { if (!i) return nullptr; - uint idx = i->id % alloc; + uint idx = i.id % alloc; while (1) { Heap::String *e = entriesById[idx]; Q_ASSERT(e); @@ -201,12 +197,12 @@ Heap::String *IdentifierTable::stringFromIdentifier(const Identifier *i) const } } -Identifier *IdentifierTable::identifier(const QString &s) +Identifier IdentifierTable::identifier(const QString &s) { return insertString(s)->identifier; } -Identifier *IdentifierTable::identifier(const char *s, int len) +Identifier IdentifierTable::identifier(const char *s, int len) { uint subtype; uint hash = String::createHashValue(s, len, &subtype); |