From b58711804e9cca641927dbdebe281488e475352b Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 6 Apr 2018 13:41:29 +0200 Subject: Use Identifier by value and don't new them anymore Change-Id: Ib25c08027013217657beb2675dafa9a8c85cbaf9 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4context.cpp | 8 ++--- src/qml/jsruntime/qv4engine_p.h | 4 +-- src/qml/jsruntime/qv4identifier.cpp | 26 ++++++++-------- src/qml/jsruntime/qv4identifier_p.h | 19 ++++++++---- src/qml/jsruntime/qv4identifiertable.cpp | 24 ++++++--------- src/qml/jsruntime/qv4identifiertable_p.h | 14 ++++----- src/qml/jsruntime/qv4internalclass.cpp | 52 ++++++++++++++++---------------- src/qml/jsruntime/qv4internalclass_p.h | 26 ++++++++-------- src/qml/jsruntime/qv4lookup.cpp | 8 ++--- src/qml/jsruntime/qv4lookup_p.h | 2 +- src/qml/jsruntime/qv4managed_p.h | 2 +- src/qml/jsruntime/qv4object.cpp | 16 +++++----- src/qml/jsruntime/qv4string.cpp | 2 +- src/qml/jsruntime/qv4string_p.h | 8 ++--- src/qml/qml/v8/qv8engine.cpp | 6 ++-- 15 files changed, 111 insertions(+), 106 deletions(-) (limited to 'src/qml') diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index bd2e0faebf..c81af767fa 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -175,7 +175,7 @@ void ExecutionContext::createMutableBinding(String *name, bool deletable) bool ExecutionContext::deleteProperty(String *name) { name->makeIdentifier(); - Identifier *id = name->identifier(); + Identifier id = name->identifier(); Heap::ExecutionContext *ctx = d(); for (; ctx; ctx = ctx->outer) { @@ -211,7 +211,7 @@ bool ExecutionContext::deleteProperty(String *name) ExecutionContext::Error ExecutionContext::setProperty(String *name, const Value &value) { name->makeIdentifier(); - Identifier *id = name->identifier(); + Identifier id = name->identifier(); QV4::ExecutionEngine *v4 = engine(); Heap::ExecutionContext *ctx = d(); @@ -274,7 +274,7 @@ ReturnedValue ExecutionContext::getProperty(String *name) case Heap::ExecutionContext::Type_BlockContext: case Heap::ExecutionContext::Type_CallContext: { Heap::CallContext *c = static_cast(ctx); - Identifier *id = name->identifier(); + Identifier id = name->identifier(); uint index = c->internalClass->find(id); if (index < UINT_MAX) @@ -311,7 +311,7 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Value *base) case Heap::ExecutionContext::Type_CallContext: { Heap::CallContext *c = static_cast(ctx); name->makeIdentifier(); - Identifier *id = name->identifier(); + Identifier id = name->identifier(); uint index = c->internalClass->find(id); if (index < UINT_MAX) diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index 8e5108b399..69c62261d2 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -158,9 +158,9 @@ public: QJSEngine *publicEngine; private: - int stringOrSymbolId = 0; + quintptr currentIdentifier = 0; public: - int nextStringOrSymbolId() { return ++stringOrSymbolId; } + Identifier nextIdentifier() { return Identifier{ ++currentIdentifier }; } enum JSObjects { RootContext, diff --git a/src/qml/jsruntime/qv4identifier.cpp b/src/qml/jsruntime/qv4identifier.cpp index 69d44f89c4..0bde74b718 100644 --- a/src/qml/jsruntime/qv4identifier.cpp +++ b/src/qml/jsruntime/qv4identifier.cpp @@ -93,7 +93,7 @@ void IdentifierHash::detach() } -IdentifierHashEntry *IdentifierHash::addEntry(const Identifier *identifier) +IdentifierHashEntry *IdentifierHash::addEntry(Identifier identifier) { // fill up to max 50% bool grow = (d->alloc <= d->size*2); @@ -107,8 +107,8 @@ IdentifierHashEntry *IdentifierHash::addEntry(const Identifier *identifier) const IdentifierHashEntry &e = d->entries[i]; if (!e.identifier) continue; - uint idx = e.identifier->id % newAlloc; - while (newEntries[idx].identifier) { + uint idx = e.identifier.id % newAlloc; + while (newEntries[idx].identifier.isValid()) { ++idx; idx %= newAlloc; } @@ -119,8 +119,8 @@ IdentifierHashEntry *IdentifierHash::addEntry(const Identifier *identifier) d->alloc = newAlloc; } - uint idx = identifier->id % d->alloc; - while (d->entries[idx].identifier) { + uint idx = identifier.id % d->alloc; + while (d->entries[idx].identifier.isValid()) { Q_ASSERT(d->entries[idx].identifier != identifier); ++idx; idx %= d->alloc; @@ -130,13 +130,13 @@ IdentifierHashEntry *IdentifierHash::addEntry(const Identifier *identifier) return d->entries + idx; } -const IdentifierHashEntry *IdentifierHash::lookup(const Identifier *identifier) const +const IdentifierHashEntry *IdentifierHash::lookup(Identifier identifier) const { if (!d) return nullptr; Q_ASSERT(d->entries); - uint idx = identifier->id % d->alloc; + uint idx = identifier.id % d->alloc; while (1) { if (!d->entries[idx].identifier) return nullptr; @@ -152,7 +152,7 @@ const IdentifierHashEntry *IdentifierHash::lookup(const QString &str) const if (!d) return nullptr; - Identifier *id = d->identifierTable->identifier(str); + Identifier id = d->identifierTable->identifier(str); return lookup(id); } @@ -160,18 +160,18 @@ const IdentifierHashEntry *IdentifierHash::lookup(String *str) const { if (!d) return nullptr; - if (str->d()->identifier) + if (str->d()->identifier.isValid()) return lookup(str->d()->identifier); return lookup(str->toQString()); } -const Identifier *IdentifierHash::toIdentifier(const QString &str) const +const Identifier IdentifierHash::toIdentifier(const QString &str) const { Q_ASSERT(d); return d->identifierTable->identifier(str); } -const Identifier *IdentifierHash::toIdentifier(Heap::String *str) const +const Identifier IdentifierHash::toIdentifier(Heap::String *str) const { Q_ASSERT(d); return d->identifierTable->identifier(str); @@ -182,8 +182,8 @@ QString QV4::IdentifierHash::findId(int value) const IdentifierHashEntry *e = d->entries; IdentifierHashEntry *end = e + d->alloc; while (e < end) { - if (e->identifier && e->value == value) - return d->identifierTable->stringFromIdentifier(e->identifier)->toQString(); + if (e->identifier.isValid() && e->value == value) + return d->identifierTable->stringForId(e->identifier)->toQString(); ++e; } return QString(); diff --git a/src/qml/jsruntime/qv4identifier_p.h b/src/qml/jsruntime/qv4identifier_p.h index f3935950c8..660cc2db05 100644 --- a/src/qml/jsruntime/qv4identifier_p.h +++ b/src/qml/jsruntime/qv4identifier_p.h @@ -66,12 +66,19 @@ struct ExecutionEngine; struct Identifier { - uint id; + quintptr id; + + static Identifier invalid() { return Identifier{0}; } + bool isValid() const { return id != 0; } + bool operator !() const { return id == 0; } + bool operator ==(const Identifier &other) const { return id == other.id; } + bool operator !=(const Identifier &other) const { return id != other.id; } + bool operator <(const Identifier &other) const { return id < other.id; } }; struct IdentifierHashEntry { - const Identifier *identifier; + Identifier identifier; int value; }; @@ -116,12 +123,12 @@ struct IdentifierHash QString findId(int value) const; protected: - IdentifierHashEntry *addEntry(const Identifier *i); - const IdentifierHashEntry *lookup(const Identifier *identifier) const; + IdentifierHashEntry *addEntry(Identifier i); + const IdentifierHashEntry *lookup(Identifier identifier) const; const IdentifierHashEntry *lookup(const QString &str) const; const IdentifierHashEntry *lookup(String *str) const; - const Identifier *toIdentifier(const QString &str) const; - const Identifier *toIdentifier(Heap::String *str) const; + const Identifier toIdentifier(const QString &str) const; + const Identifier toIdentifier(Heap::String *str) const; }; 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); diff --git a/src/qml/jsruntime/qv4identifiertable_p.h b/src/qml/jsruntime/qv4identifiertable_p.h index 0c8de01f71..dce270e337 100644 --- a/src/qml/jsruntime/qv4identifiertable_p.h +++ b/src/qml/jsruntime/qv4identifiertable_p.h @@ -78,21 +78,21 @@ public: Heap::String *insertString(const QString &s); - Identifier *identifier(const Heap::String *str) { - if (str->identifier) + Identifier identifier(const Heap::String *str) { + if (str->identifier.isValid()) return str->identifier; return identifierImpl(str); } - Identifier *identifier(const QV4::String *str) { + Identifier identifier(const QV4::String *str) { return identifier(str->d()); } - Identifier *identifier(const QString &s); - Identifier *identifier(const char *s, int len); + Identifier identifier(const QString &s); + Identifier identifier(const char *s, int len); - Identifier *identifierImpl(const Heap::String *str); + Identifier identifierImpl(const Heap::String *str); - Q_QML_PRIVATE_EXPORT Heap::String *stringFromIdentifier(const Identifier *i) const; + Q_QML_PRIVATE_EXPORT Heap::String *stringForId(Identifier i) const; void mark(MarkStack *markStack) { for (int i = 0; i < alloc; ++i) { diff --git a/src/qml/jsruntime/qv4internalclass.cpp b/src/qml/jsruntime/qv4internalclass.cpp index 532d35962c..de3f6e0ee6 100644 --- a/src/qml/jsruntime/qv4internalclass.cpp +++ b/src/qml/jsruntime/qv4internalclass.cpp @@ -77,8 +77,8 @@ void PropertyHash::addEntry(const PropertyHash::Entry &entry, int classSize) if (classSize < d->size || grow) detach(grow, classSize); - uint idx = entry.identifier->id % d->alloc; - while (d->entries[idx].identifier) { + uint idx = entry.identifier.id % d->alloc; + while (d->entries[idx].identifier.isValid()) { ++idx; idx %= d->alloc; } @@ -86,20 +86,20 @@ void PropertyHash::addEntry(const PropertyHash::Entry &entry, int classSize) ++d->size; } -int PropertyHash::removeIdentifier(Identifier *identifier, int classSize) +int PropertyHash::removeIdentifier(Identifier identifier, int classSize) { int val = -1; PropertyHashData *dd = new PropertyHashData(d->numBits); for (int i = 0; i < d->alloc; ++i) { const Entry &e = d->entries[i]; - if (!e.identifier || e.index >= static_cast(classSize)) + if (!e.identifier.isValid() || e.index >= static_cast(classSize)) continue; if (e.identifier == identifier) { val = e.index; continue; } - uint idx = e.identifier->id % dd->alloc; - while (dd->entries[idx].identifier) { + uint idx = e.identifier.id % dd->alloc; + while (dd->entries[idx].identifier.isValid()) { ++idx; idx %= dd->alloc; } @@ -124,8 +124,8 @@ void PropertyHash::detach(bool grow, int classSize) const Entry &e = d->entries[i]; if (!e.identifier || e.index >= static_cast(classSize)) continue; - uint idx = e.identifier->id % dd->alloc; - while (dd->entries[idx].identifier) { + uint idx = e.identifier.id % dd->alloc; + while (dd->entries[idx].identifier.isValid()) { ++idx; idx %= dd->alloc; } @@ -143,7 +143,7 @@ void InternalClass::init(ExecutionEngine *engine) { Base::init(); new (&propertyTable) PropertyHash(); - new (&nameMap) SharedInternalClassData(); + new (&nameMap) SharedInternalClassData(); new (&propertyData) SharedInternalClassData(); new (&transitions) std::vector(); @@ -168,7 +168,7 @@ void InternalClass::init(Heap::InternalClass *other) Base::init(); Q_ASSERT(!other->isFrozen); new (&propertyTable) PropertyHash(other->propertyTable); - new (&nameMap) SharedInternalClassData(other->nameMap); + new (&nameMap) SharedInternalClassData(other->nameMap); new (&propertyData) SharedInternalClassData(other->propertyData); new (&transitions) std::vector(); @@ -197,7 +197,7 @@ void InternalClass::destroy() parent->removeChildEntry(this); propertyTable.~PropertyHash(); - nameMap.~SharedInternalClassData(); + nameMap.~SharedInternalClassData(); propertyData.~SharedInternalClassData(); transitions.~vector(); engine = nullptr; @@ -260,12 +260,12 @@ static void addDummyEntry(InternalClass *newClass, PropertyHash::Entry e) { // add a dummy entry, since we need two entries for accessors newClass->propertyTable.addEntry(e, newClass->size); - newClass->nameMap.add(newClass->size, nullptr); + newClass->nameMap.add(newClass->size, Identifier::invalid()); newClass->propertyData.add(newClass->size, PropertyAttributes()); ++newClass->size; } -Heap::InternalClass *InternalClass::changeMember(Identifier *identifier, PropertyAttributes data, uint *index) +Heap::InternalClass *InternalClass::changeMember(Identifier identifier, PropertyAttributes data, uint *index) { data.resolve(); uint idx = find(identifier); @@ -287,11 +287,11 @@ Heap::InternalClass *InternalClass::changeMember(Identifier *identifier, Propert if (data.isAccessor() != propertyData.at(idx).isAccessor()) { // this changes the layout of the class, so we need to rebuild the data newClass->propertyTable = PropertyHash(); - newClass->nameMap = SharedInternalClassData(); + newClass->nameMap = SharedInternalClassData(); newClass->propertyData = SharedInternalClassData(); newClass->size = 0; for (uint i = 0; i < size; ++i) { - Identifier *identifier = nameMap.at(i); + Identifier identifier = nameMap.at(i); PropertyHash::Entry e = { identifier, newClass->size }; if (!identifier) e.identifier = nameMap.at(i - 1); @@ -327,7 +327,7 @@ Heap::InternalClass *InternalClass::changePrototypeImpl(Heap::Object *proto) Q_ASSERT(prototype != proto); Q_ASSERT(!proto || proto->internalClass->isUsedAsProto); - Transition temp = { { nullptr }, nullptr, Transition::PrototypeChange }; + Transition temp = { { Identifier::invalid() }, nullptr, Transition::PrototypeChange }; temp.prototype = proto; Transition &t = lookupOrInsertTransition(temp); @@ -347,7 +347,7 @@ Heap::InternalClass *InternalClass::changeVTableImpl(const VTable *vt) { Q_ASSERT(vtable != vt); - Transition temp = { { nullptr }, nullptr, Transition::VTableChange }; + Transition temp = { { Identifier::invalid() }, nullptr, Transition::VTableChange }; temp.vtable = vt; Transition &t = lookupOrInsertTransition(temp); @@ -369,7 +369,7 @@ Heap::InternalClass *InternalClass::nonExtensible() if (!extensible) return this; - Transition temp = { { nullptr }, nullptr, Transition::NotExtensible}; + Transition temp = { { Identifier::invalid() }, nullptr, Transition::NotExtensible}; Transition &t = lookupOrInsertTransition(temp); if (t.lookup) return t.lookup; @@ -405,7 +405,7 @@ Heap::InternalClass *InternalClass::addMember(QV4::String *string, PropertyAttri return addMember(string->identifier(), data, index); } -Heap::InternalClass *InternalClass::addMember(Identifier *identifier, PropertyAttributes data, uint *index) +Heap::InternalClass *InternalClass::addMember(Identifier identifier, PropertyAttributes data, uint *index) { data.resolve(); @@ -415,7 +415,7 @@ Heap::InternalClass *InternalClass::addMember(Identifier *identifier, PropertyAt return addMemberImpl(identifier, data, index); } -Heap::InternalClass *InternalClass::addMemberImpl(Identifier *identifier, PropertyAttributes data, uint *index) +Heap::InternalClass *InternalClass::addMemberImpl(Identifier identifier, PropertyAttributes data, uint *index) { Transition temp = { { identifier }, nullptr, (int)data.flags() }; Transition &t = lookupOrInsertTransition(temp); @@ -455,7 +455,7 @@ void InternalClass::removeChildEntry(InternalClass *child) } -void InternalClass::removeMember(QV4::Object *object, Identifier *identifier) +void InternalClass::removeMember(QV4::Object *object, Identifier identifier) { Heap::InternalClass *oldClass = object->internalClass(); Q_ASSERT(oldClass->propertyTable.lookup(identifier) < oldClass->size); @@ -468,7 +468,7 @@ void InternalClass::removeMember(QV4::Object *object, Identifier *identifier) Heap::InternalClass *newClass = oldClass->engine->newClass(oldClass); // simply make the entry inaccessible int idx = newClass->propertyTable.removeIdentifier(identifier, oldClass->size); - newClass->nameMap.set(idx, nullptr); + newClass->nameMap.set(idx, Identifier::invalid()); newClass->propertyData.set(idx, PropertyAttributes()); t.lookup = newClass; Q_ASSERT(t.lookup); @@ -482,7 +482,7 @@ void InternalClass::removeMember(QV4::Object *object, Identifier *identifier) uint InternalClass::find(const QV4::String *string) { engine->identifierTable->identifier(string); - const Identifier *id = string->d()->identifier; + const Identifier id = string->d()->identifier; uint index = propertyTable.lookup(id); if (index < size) @@ -512,7 +512,7 @@ Heap::InternalClass *InternalClass::sealed() return this; } - Transition temp = { { nullptr }, nullptr, InternalClassTransition::Sealed }; + Transition temp = { { Identifier::invalid() }, nullptr, InternalClassTransition::Sealed }; Transition &t = lookupOrInsertTransition(temp); if (t.lookup) { @@ -558,7 +558,7 @@ Heap::InternalClass *InternalClass::frozen() return this; } - Transition temp = { { nullptr }, nullptr, InternalClassTransition::Frozen }; + Transition temp = { { Identifier::invalid() }, nullptr, InternalClassTransition::Frozen }; Transition &t = lookupOrInsertTransition(temp); if (t.lookup) { @@ -606,7 +606,7 @@ Heap::InternalClass *InternalClass::asProtoClass() if (isUsedAsProto) return this; - Transition temp = { { nullptr }, nullptr, Transition::ProtoClass }; + Transition temp = { { Identifier::invalid() }, nullptr, Transition::ProtoClass }; Transition &t = lookupOrInsertTransition(temp); if (t.lookup) return t.lookup; diff --git a/src/qml/jsruntime/qv4internalclass_p.h b/src/qml/jsruntime/qv4internalclass_p.h index 11c12d012c..04dfd4b654 100644 --- a/src/qml/jsruntime/qv4internalclass_p.h +++ b/src/qml/jsruntime/qv4internalclass_p.h @@ -70,7 +70,7 @@ struct PropertyHashData; struct PropertyHash { struct Entry { - const Identifier *identifier; + Identifier identifier; uint index; }; @@ -82,8 +82,8 @@ struct PropertyHash PropertyHash &operator=(const PropertyHash &other); void addEntry(const Entry &entry, int classSize); - uint lookup(const Identifier *identifier) const; - int removeIdentifier(Identifier *identifier, int classSize); + uint lookup(Identifier identifier) const; + int removeIdentifier(Identifier identifier, int classSize); void detach(bool grow, int classSize); }; @@ -129,11 +129,11 @@ inline PropertyHash &PropertyHash::operator=(const PropertyHash &other) -inline uint PropertyHash::lookup(const Identifier *identifier) const +inline uint PropertyHash::lookup(Identifier identifier) const { Q_ASSERT(d->entries); - uint idx = identifier->id % d->alloc; + uint idx = identifier.id % d->alloc; while (1) { if (d->entries[idx].identifier == identifier) return d->entries[idx].index; @@ -237,7 +237,7 @@ struct SharedInternalClassData { struct InternalClassTransition { union { - Identifier *id; + Identifier id; const VTable *vtable; Heap::Object *prototype; }; @@ -261,6 +261,8 @@ struct InternalClassTransition { return id < other.id || (id == other.id && flags < other.flags); } }; +static_assert(sizeof(Identifier) == sizeof(VTable *), "Identifier needs to be one pointer large to map into the union above"); + namespace Heap { struct InternalClass : Base { @@ -271,7 +273,7 @@ struct InternalClass : Base { InternalClass *parent; PropertyHash propertyTable; // id to valueIndex - SharedInternalClassData nameMap; + SharedInternalClassData nameMap; SharedInternalClassData propertyData; typedef InternalClassTransition Transition; @@ -292,12 +294,12 @@ struct InternalClass : Base { static void addMember(QV4::Object *object, QV4::String *string, PropertyAttributes data, uint *index); Q_REQUIRED_RESULT InternalClass *addMember(QV4::String *string, PropertyAttributes data, uint *index = nullptr); - Q_REQUIRED_RESULT InternalClass *addMember(Identifier *identifier, PropertyAttributes data, uint *index = nullptr); - Q_REQUIRED_RESULT InternalClass *changeMember(Identifier *identifier, PropertyAttributes data, uint *index = nullptr); + Q_REQUIRED_RESULT InternalClass *addMember(Identifier identifier, PropertyAttributes data, uint *index = nullptr); + Q_REQUIRED_RESULT InternalClass *changeMember(Identifier identifier, PropertyAttributes data, uint *index = nullptr); static void changeMember(QV4::Object *object, QV4::String *string, PropertyAttributes data, uint *index = nullptr); - static void removeMember(QV4::Object *object, Identifier *identifier); + static void removeMember(QV4::Object *object, Identifier identifier); uint find(const QV4::String *string); - uint find(const Identifier *id) + uint find(const Identifier id) { uint index = propertyTable.lookup(id); if (index < size) @@ -330,7 +332,7 @@ struct InternalClass : Base { private: Q_QML_EXPORT InternalClass *changeVTableImpl(const VTable *vt); Q_QML_EXPORT InternalClass *changePrototypeImpl(Heap::Object *proto); - InternalClass *addMemberImpl(Identifier *identifier, PropertyAttributes data, uint *index); + InternalClass *addMemberImpl(Identifier identifier, PropertyAttributes data, uint *index); void removeChildEntry(InternalClass *child); friend struct ExecutionEngine; diff --git a/src/qml/jsruntime/qv4lookup.cpp b/src/qml/jsruntime/qv4lookup.cpp index fdf3d7685d..cd9583cccb 100644 --- a/src/qml/jsruntime/qv4lookup.cpp +++ b/src/qml/jsruntime/qv4lookup.cpp @@ -47,7 +47,7 @@ QT_BEGIN_NAMESPACE using namespace QV4; -void Lookup::resolveProtoGetter(Identifier *name, const Heap::Object *proto) +void Lookup::resolveProtoGetter(Identifier name, const Heap::Object *proto) { while (proto) { uint index = proto->internalClass->find(name); @@ -70,7 +70,7 @@ void Lookup::resolveProtoGetter(Identifier *name, const Heap::Object *proto) ReturnedValue Lookup::resolveGetter(ExecutionEngine *engine, const Object *object) { Heap::Object *obj = object->d(); - Identifier *name = engine->identifierTable->identifier(engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]); + Identifier name = engine->identifierTable->identifier(engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]); uint index = obj->internalClass->find(name); if (index != UINT_MAX) { @@ -125,7 +125,7 @@ ReturnedValue Lookup::resolvePrimitiveGetter(ExecutionEngine *engine, const Valu primitiveLookup.proto = engine->numberPrototype()->d(); } - Identifier *name = engine->identifierTable->identifier(engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]); + Identifier name = engine->identifierTable->identifier(engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]); protoLookup.protoId = primitiveLookup.proto->internalClass->protoId; resolveProtoGetter(name, primitiveLookup.proto); @@ -139,7 +139,7 @@ ReturnedValue Lookup::resolvePrimitiveGetter(ExecutionEngine *engine, const Valu ReturnedValue Lookup::resolveGlobalGetter(ExecutionEngine *engine) { Object *o = engine->globalObject; - Identifier *name = engine->identifierTable->identifier(engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]); + Identifier name = engine->identifierTable->identifier(engine->currentStackFrame->v4Function->compilationUnit->runtimeStrings[nameIndex]); protoLookup.protoId = o->internalClass()->protoId; resolveProtoGetter(name, o->d()); diff --git a/src/qml/jsruntime/qv4lookup_p.h b/src/qml/jsruntime/qv4lookup_p.h index 49eb66d1fb..eb6ad067d7 100644 --- a/src/qml/jsruntime/qv4lookup_p.h +++ b/src/qml/jsruntime/qv4lookup_p.h @@ -117,7 +117,7 @@ struct Lookup { ReturnedValue resolveGetter(ExecutionEngine *engine, const Object *object); ReturnedValue resolvePrimitiveGetter(ExecutionEngine *engine, const Value &object); ReturnedValue resolveGlobalGetter(ExecutionEngine *engine); - void resolveProtoGetter(Identifier *name, const Heap::Object *proto); + void resolveProtoGetter(Identifier name, const Heap::Object *proto); static ReturnedValue getterGeneric(Lookup *l, ExecutionEngine *engine, const Value &object); static ReturnedValue getterTwoClasses(Lookup *l, ExecutionEngine *engine, const Value &object); diff --git a/src/qml/jsruntime/qv4managed_p.h b/src/qml/jsruntime/qv4managed_p.h index b35788a711..7c5bda3efb 100644 --- a/src/qml/jsruntime/qv4managed_p.h +++ b/src/qml/jsruntime/qv4managed_p.h @@ -273,7 +273,7 @@ struct InternalClass : Managed Q_REQUIRED_RESULT Heap::InternalClass *addMember(QV4::String *string, PropertyAttributes data, uint *index = 0) { return d()->addMember(string, data, index); } - Q_REQUIRED_RESULT Heap::InternalClass *addMember(Identifier *identifier, PropertyAttributes data, uint *index = 0) { + Q_REQUIRED_RESULT Heap::InternalClass *addMember(Identifier identifier, PropertyAttributes data, uint *index = 0) { return d()->addMember(identifier, data, index); } diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index d7cad2231e..56f93ef1ce 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -267,7 +267,7 @@ void Object::getOwnProperty(String *name, PropertyAttributes *attrs, Property *p return getOwnProperty(idx, attrs, p); name->makeIdentifier(); - Identifier *id = name->identifier(); + Identifier id = name->identifier(); uint member = internalClass()->find(id); if (member < UINT_MAX) { @@ -309,7 +309,7 @@ MemberData::Index Object::getValueOrSetter(String *name, PropertyAttributes *att Q_ASSERT(name->asArrayIndex() == UINT_MAX); name->makeIdentifier(); - Identifier *id = name->identifier(); + Identifier id = name->identifier(); Heap::Object *o = d(); while (o) { @@ -389,7 +389,7 @@ bool Object::hasOwnProperty(String *name) const return hasOwnProperty(idx); name->makeIdentifier(); - Identifier *id = name->identifier(); + Identifier id = name->identifier(); if (internalClass()->find(id) < UINT_MAX) return true; @@ -449,7 +449,7 @@ PropertyAttributes Object::query(const Managed *m, String *name) return queryIndexed(m, idx); name->makeIdentifier(); - Identifier *id = name->identifier(); + Identifier id = name->identifier(); const Object *o = static_cast(m); idx = o->internalClass()->find(id); @@ -529,7 +529,7 @@ void Object::advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint * } while (it->memberIndex < o->internalClass()->size) { - Identifier *n = o->internalClass()->nameMap.at(it->memberIndex); + Identifier n = o->internalClass()->nameMap.at(it->memberIndex); if (!n) { // accessor properties have a dummy entry with n == 0 ++it->memberIndex; @@ -540,7 +540,7 @@ void Object::advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint * PropertyAttributes a = o->internalClass()->propertyData[it->memberIndex]; ++it->memberIndex; if (!(it->flags & ObjectIterator::EnumerableOnly) || a.isEnumerable()) { - name->setM(o->engine()->identifierTable->stringFromIdentifier(n)); + name->setM(o->engine()->identifierTable->stringForId(n)); *attrs = a; pd->value = *o->propertyData(idx); if (a.isAccessor()) @@ -560,7 +560,7 @@ ReturnedValue Object::internalGet(String *name, bool *hasProperty) const return getIndexed(idx, hasProperty); name->makeIdentifier(); - Identifier *id = name->identifier(); + Identifier id = name->identifier(); Heap::Object *o = d(); while (o) { @@ -627,7 +627,7 @@ bool Object::internalPut(String *name, const Value &value) return putIndexed(idx, value); name->makeIdentifier(); - Identifier *id = name->identifier(); + Identifier id = name->identifier(); MemberData::Index memberIndex{nullptr, nullptr}; uint member = internalClass()->find(id); diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp index 57832a0068..a7a8868bdd 100644 --- a/src/qml/jsruntime/qv4string.cpp +++ b/src/qml/jsruntime/qv4string.cpp @@ -175,7 +175,7 @@ void Heap::String::simplifyString() const text = result.data_ptr(); text->ref.ref(); const ComplexString *cs = static_cast(this); - identifier = nullptr; + identifier = Identifier::invalid(); cs->left = cs->right = nullptr; internalClass->engine->memoryManager->changeUnmanagedHeapSizeUsage(qptrdiff(text->size) * (qptrdiff)sizeof(QChar)); diff --git a/src/qml/jsruntime/qv4string_p.h b/src/qml/jsruntime/qv4string_p.h index 72c4057b20..200d979f24 100644 --- a/src/qml/jsruntime/qv4string_p.h +++ b/src/qml/jsruntime/qv4string_p.h @@ -108,7 +108,7 @@ struct Q_QML_PRIVATE_EXPORT String : Base { if (hashValue() != other->hashValue()) return false; Q_ASSERT(subtype < StringType_Complex); - if (identifier && identifier == other->identifier) + if (identifier.isValid() && identifier == other->identifier) return true; if (subtype == Heap::String::StringType_ArrayIndex && other->subtype == Heap::String::StringType_ArrayIndex) return true; @@ -119,7 +119,7 @@ struct Q_QML_PRIVATE_EXPORT String : Base { bool startsWithUpper() const; mutable QStringData *text; - mutable Identifier *identifier; + mutable Identifier identifier; mutable uint subtype; mutable uint stringHash; private: @@ -192,7 +192,7 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed { uint toUInt(bool *ok) const; void makeIdentifier() const { - if (d()->identifier) + if (d()->identifier.isValid()) return; makeIdentifierImpl(); } @@ -214,7 +214,7 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed { bool startsWithUpper() const { return d()->startsWithUpper(); } - Identifier *identifier() const { return d()->identifier; } + Identifier identifier() const { return d()->identifier; } protected: static bool isEqualTo(Managed *that, Managed *o); diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 7106583e6d..81f1f89c92 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -207,9 +207,9 @@ void QV8Engine::initializeGlobal() { for (uint i = 0; i < m_v4Engine->globalObject->internalClass()->size; ++i) { - if (m_v4Engine->globalObject->internalClass()->nameMap.at(i)) { - QV4::Identifier *id = m_v4Engine->globalObject->internalClass()->nameMap.at(i); - m_illegalNames.insert(m_v4Engine->identifierTable->stringFromIdentifier(id)->toQString()); + if (m_v4Engine->globalObject->internalClass()->nameMap.at(i).isValid()) { + QV4::Identifier id = m_v4Engine->globalObject->internalClass()->nameMap.at(i); + m_illegalNames.insert(m_v4Engine->identifierTable->stringForId(id)->toQString()); } } } -- cgit v1.2.3