diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2014-11-12 20:07:27 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2014-11-21 16:36:10 +0100 |
commit | f62bf4e76d9ae9bf685e37ace3dc6d2365e2f82f (patch) | |
tree | e3fe77546b69c0a1b82dec7306896a4b31876954 /src/qml | |
parent | f58b5229a31e9fec49b4eb055c56f9a78e423866 (diff) |
Changed InternalClass to store Identifier* instead of String*
All members are identifiers anyway, so this gets rid of a ### and
also simplifies some of the call sites by removing the need for a
scoped string.
Change-Id: Ic6b550cdb97afa5a4b0fa7e9b13e7768ed3f6bd8
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/compiler/qv4compileddata.cpp | 5 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4context.cpp | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4context_p.h | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4debugging.cpp | 9 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4function.cpp | 7 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4internalclass.cpp | 48 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4internalclass_p.h | 8 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4lookup.cpp | 6 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4object.cpp | 6 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4script.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8engine.cpp | 2 |
11 files changed, 54 insertions, 49 deletions
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp index f327f9b70e..65a14a302a 100644 --- a/src/qml/compiler/qv4compileddata.cpp +++ b/src/qml/compiler/qv4compileddata.cpp @@ -117,15 +117,12 @@ QV4::Function *CompilationUnit::linkToEngine(ExecutionEngine *engine) if (data->jsClassTableSize) { runtimeClasses = (QV4::InternalClass**)malloc(data->jsClassTableSize * sizeof(QV4::InternalClass*)); - Scope scope(engine); - ScopedString memberName(scope); - for (uint i = 0; i < data->jsClassTableSize; ++i) { int memberCount = 0; const CompiledData::JSClassMember *member = data->jsClassAt(i, &memberCount); QV4::InternalClass *klass = engine->objectClass; for (int j = 0; j < memberCount; ++j, ++member) - klass = klass->addMember((memberName = runtimeStrings[member->nameOffset]), member->isAccessor ? QV4::Attr_Accessor : QV4::Attr_Data); + klass = klass->addMember(runtimeStrings[member->nameOffset]->identifier, member->isAccessor ? QV4::Attr_Accessor : QV4::Attr_Data); runtimeClasses[i] = klass; } diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index 378bcde624..fee2be30dc 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -182,7 +182,7 @@ Heap::CallContext::CallContext(ExecutionEngine *engine, QV4::Object *qml, QV4::F std::fill(locals, locals + function->varCount(), Primitive::undefinedValue()); } -String * const *CallContext::formals() const +Identifier * const *CallContext::formals() const { return (d()->function && d()->function->function) ? d()->function->function->internalClass->nameMap.constData() : 0; } @@ -192,7 +192,7 @@ unsigned int CallContext::formalCount() const return d()->function ? d()->function->formalParameterCount() : 0; } -String * const *CallContext::variables() const +Identifier * const *CallContext::variables() const { return (d()->function && d()->function->function) ? d()->function->function->internalClass->nameMap.constData() + d()->function->formalParameterCount() : 0; } diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index 298ac0acb4..7057e94457 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -171,9 +171,9 @@ struct CallContext : public ExecutionContext V4_MANAGED(CallContext, ExecutionContext) // formals are in reverse order - String * const *formals() const; + Identifier * const *formals() const; unsigned int formalCount() const; - String * const *variables() const; + Identifier * const *variables() const; unsigned int variableCount() const; inline ReturnedValue argument(int i); diff --git a/src/qml/jsruntime/qv4debugging.cpp b/src/qml/jsruntime/qv4debugging.cpp index 85c03914a7..8211aa584e 100644 --- a/src/qml/jsruntime/qv4debugging.cpp +++ b/src/qml/jsruntime/qv4debugging.cpp @@ -39,6 +39,7 @@ #include "qv4runtime_p.h" #include "qv4script_p.h" #include "qv4objectiterator_p.h" +#include "qv4identifier_p.h" #include <iostream> #include <algorithm> @@ -327,8 +328,8 @@ void Debugger::collectArgumentsInContext(Collector *collector, int frameNr, int int nFormals = ctxt->formalCount(); for (unsigned i = 0, ei = nFormals; i != ei; ++i) { QString qName; - if (String *name = ctxt->formals()[nFormals - i - 1]) - qName = name->toQString(); + if (Identifier *name = ctxt->formals()[nFormals - i - 1]) + qName = name->string; v = ctxt->argument(i); collector->collect(qName, v); } @@ -373,8 +374,8 @@ void Debugger::collectLocalsInContext(Collector *collector, int frameNr, int sco ScopedValue v(scope); for (unsigned i = 0, ei = ctxt->variableCount(); i != ei; ++i) { QString qName; - if (String *name = ctxt->variables()[i]) - qName = name->toQString(); + if (Identifier *name = ctxt->variables()[i]) + qName = name->string; v = ctxt->d()->locals[i]; collector->collect(qName, v); } diff --git a/src/qml/jsruntime/qv4function.cpp b/src/qml/jsruntime/qv4function.cpp index 37e19c559b..ef8b1eafd9 100644 --- a/src/qml/jsruntime/qv4function.cpp +++ b/src/qml/jsruntime/qv4function.cpp @@ -71,11 +71,8 @@ Function::Function(ExecutionEngine *engine, CompiledData::CompilationUnit *unit, } const quint32 *localsIndices = compiledFunction->localsTable(); - ScopedString local(scope); - for (quint32 i = 0; i < compiledFunction->nLocals; ++i) { - local = compilationUnit->runtimeStrings[localsIndices[i]]; - internalClass = internalClass->addMember(local, Attr_NotConfigurable); - } + for (quint32 i = 0; i < compiledFunction->nLocals; ++i) + internalClass = internalClass->addMember(compilationUnit->runtimeStrings[localsIndices[i]]->identifier, Attr_NotConfigurable); } Function::~Function() diff --git a/src/qml/jsruntime/qv4internalclass.cpp b/src/qml/jsruntime/qv4internalclass.cpp index 7247228091..bd76fa6ec7 100644 --- a/src/qml/jsruntime/qv4internalclass.cpp +++ b/src/qml/jsruntime/qv4internalclass.cpp @@ -147,7 +147,7 @@ InternalClass::InternalClass(const QV4::InternalClass &other) void InternalClass::changeMember(Object *object, String *string, PropertyAttributes data, uint *index) { uint idx; - InternalClass *newClass = object->internalClass()->changeMember(string, data, &idx); + InternalClass *newClass = object->internalClass()->changeMember(string->identifier(), data, &idx); if (index) *index = idx; @@ -161,10 +161,10 @@ void InternalClass::changeMember(Object *object, String *string, PropertyAttribu object->setInternalClass(newClass); } -InternalClass *InternalClass::changeMember(String *string, PropertyAttributes data, uint *index) +InternalClass *InternalClass::changeMember(Identifier *identifier, PropertyAttributes data, uint *index) { data.resolve(); - uint idx = find(string); + uint idx = find(identifier); Q_ASSERT(idx != UINT_MAX); if (index) @@ -173,7 +173,7 @@ InternalClass *InternalClass::changeMember(String *string, PropertyAttributes da if (data == propertyData.at(idx)) return this; - Transition t = { { string->d()->identifier }, (int)data.flags() }; + Transition t = { { identifier }, (int)data.flags() }; QHash<Transition, InternalClass *>::const_iterator tit = transitions.constFind(t); if (tit != transitions.constEnd()) return tit.value(); @@ -273,28 +273,32 @@ void InternalClass::addMember(Object *object, String *string, PropertyAttributes } uint idx; - InternalClass *newClass = object->internalClass()->addMemberImpl(string, data, &idx); + InternalClass *newClass = object->internalClass()->addMemberImpl(string->identifier(), data, &idx); if (index) *index = idx; object->setInternalClass(newClass); } - InternalClass *InternalClass::addMember(String *string, PropertyAttributes data, uint *index) { - data.resolve(); engine->identifierTable->identifier(string); + return addMember(string->identifier(), data, index); +} - if (propertyTable.lookup(string->d()->identifier) < size) - return changeMember(string, data, index); +InternalClass *InternalClass::addMember(Identifier *identifier, PropertyAttributes data, uint *index) +{ + data.resolve(); + + if (propertyTable.lookup(identifier) < size) + return changeMember(identifier, data, index); - return addMemberImpl(string, data, index); + return addMemberImpl(identifier, data, index); } -InternalClass *InternalClass::addMemberImpl(String *string, PropertyAttributes data, uint *index) +InternalClass *InternalClass::addMemberImpl(Identifier *identifier, PropertyAttributes data, uint *index) { - Transition t = { { string->d()->identifier }, (int)data.flags() }; + Transition t = { { identifier }, (int)data.flags() }; QHash<Transition, InternalClass *>::const_iterator tit = transitions.constFind(t); if (index) @@ -304,15 +308,10 @@ InternalClass *InternalClass::addMemberImpl(String *string, PropertyAttributes d // create a new class and add it to the tree InternalClass *newClass = engine->newClass(*this); - PropertyHash::Entry e = { string->d()->identifier, newClass->size }; + PropertyHash::Entry e = { identifier, newClass->size }; newClass->propertyTable.addEntry(e, newClass->size); - // The incoming string can come from anywhere, so make sure to - // store a string in the nameMap that's guaranteed to get - // marked properly during GC. - // #### GC - String *name = reinterpret_cast<String*>(engine->newIdentifier(string->toQString())); - newClass->nameMap.add(newClass->size, name); + newClass->nameMap.add(newClass->size, identifier); newClass->propertyData.add(newClass->size, data); ++newClass->size; if (data.isAccessor()) { @@ -369,6 +368,15 @@ uint InternalClass::find(const String *string) return UINT_MAX; } +uint InternalClass::find(const Identifier *id) +{ + uint index = propertyTable.lookup(id); + if (index < size) + return index; + + return UINT_MAX; +} + InternalClass *InternalClass::sealed() { if (m_sealed) @@ -418,7 +426,7 @@ void InternalClass::destroy() engine = 0; propertyTable.~PropertyHash(); - nameMap.~SharedInternalClassData<String *>(); + nameMap.~SharedInternalClassData<Identifier *>(); propertyData.~SharedInternalClassData<PropertyAttributes>(); if (m_sealed) diff --git a/src/qml/jsruntime/qv4internalclass_p.h b/src/qml/jsruntime/qv4internalclass_p.h index 972c341992..14dbbe713f 100644 --- a/src/qml/jsruntime/qv4internalclass_p.h +++ b/src/qml/jsruntime/qv4internalclass_p.h @@ -212,7 +212,7 @@ struct InternalClass : public QQmlJS::Managed { const ManagedVTable *vtable; PropertyHash propertyTable; // id to valueIndex - SharedInternalClassData<String *> nameMap; + SharedInternalClassData<Identifier *> nameMap; SharedInternalClassData<PropertyAttributes> propertyData; typedef InternalClassTransition Transition; @@ -228,10 +228,12 @@ struct InternalClass : public QQmlJS::Managed { InternalClass *changeVTable(const ManagedVTable *vt); static void addMember(Object *object, String *string, PropertyAttributes data, uint *index); InternalClass *addMember(String *string, PropertyAttributes data, uint *index = 0); - InternalClass *changeMember(String *string, PropertyAttributes data, uint *index = 0); + InternalClass *addMember(Identifier *identifier, PropertyAttributes data, uint *index = 0); + InternalClass *changeMember(Identifier *identifier, PropertyAttributes data, uint *index = 0); static void changeMember(Object *object, String *string, PropertyAttributes data, uint *index = 0); static void removeMember(Object *object, Identifier *id); uint find(const String *s); + uint find(const Identifier *id); InternalClass *sealed(); InternalClass *frozen(); @@ -239,7 +241,7 @@ struct InternalClass : public QQmlJS::Managed { void destroy(); private: - InternalClass *addMemberImpl(String *string, PropertyAttributes data, uint *index); + InternalClass *addMemberImpl(Identifier *identifier, PropertyAttributes data, uint *index); friend struct ExecutionEngine; InternalClass(ExecutionEngine *engine); InternalClass(const InternalClass &other); diff --git a/src/qml/jsruntime/qv4lookup.cpp b/src/qml/jsruntime/qv4lookup.cpp index 0266e0504b..97270a3655 100644 --- a/src/qml/jsruntime/qv4lookup.cpp +++ b/src/qml/jsruntime/qv4lookup.cpp @@ -42,8 +42,7 @@ using namespace QV4; ReturnedValue Lookup::lookup(ValueRef thisObject, Object *obj, PropertyAttributes *attrs) { ExecutionEngine *engine = obj->engine(); - Scope scope(engine); - ScopedString name(scope, engine->currentContext()->d()->compilationUnit->runtimeStrings[nameIndex]); + Identifier *name = engine->currentContext()->d()->compilationUnit->runtimeStrings[nameIndex]->identifier; int i = 0; while (i < Size && obj) { classList[i] = obj->internalClass(); @@ -76,8 +75,7 @@ ReturnedValue Lookup::lookup(Object *obj, PropertyAttributes *attrs) { Object *thisObject = obj; ExecutionEngine *engine = obj->engine(); - Scope scope(engine); - ScopedString name(scope, engine->currentContext()->d()->compilationUnit->runtimeStrings[nameIndex]); + Identifier *name = engine->currentContext()->d()->compilationUnit->runtimeStrings[nameIndex]->identifier; int i = 0; while (i < Size && obj) { classList[i] = obj->internalClass(); diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index d95c8cf444..2b89a37771 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -42,6 +42,7 @@ #include "qv4scopedvalue_p.h" #include "qv4memberdata_p.h" #include "qv4objectiterator_p.h" +#include "qv4identifier_p.h" #include <stdint.h> @@ -553,7 +554,7 @@ void Object::advanceIterator(Managed *m, ObjectIterator *it, String *&name, uint } while (it->memberIndex < o->internalClass()->size) { - String *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; @@ -564,7 +565,8 @@ void Object::advanceIterator(Managed *m, ObjectIterator *it, String *&name, uint PropertyAttributes a = o->internalClass()->propertyData[it->memberIndex]; ++it->memberIndex; if (!(it->flags & ObjectIterator::EnumerableOnly) || a.isEnumerable()) { - name = n; + // #### GC + name = reinterpret_cast<QV4::String*>(m->engine()->newString(n->string)); *attrs = a; pd->copy(*p, a); return; diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index 07e6035380..8ae4b0e0d8 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -261,8 +261,8 @@ void Script::parse() if (inheritContext) { CallContext *ctx = scope->asCallContext(); if (ctx) { - for (String * const *i = ctx->variables(), * const *ei = i + ctx->variableCount(); i < ei; ++i) - inheritedLocals.append(*i ? (*i)->toQString() : QString()); + for (Identifier * const *i = ctx->variables(), * const *ei = i + ctx->variableCount(); i < ei; ++i) + inheritedLocals.append(*i ? (*i)->string : QString()); } } diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 63382fa0b7..41ef719c64 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -496,7 +496,7 @@ void QV8Engine::initializeGlobal() { for (uint i = 0; i < m_v4Engine->globalObject->internalClass()->size; ++i) { if (m_v4Engine->globalObject->internalClass()->nameMap.at(i)) - m_illegalNames.insert(m_v4Engine->globalObject->internalClass()->nameMap.at(i)->toQString()); + m_illegalNames.insert(m_v4Engine->globalObject->internalClass()->nameMap.at(i)->string); } } |