From c03eedaf8c6846dc80ab014face4d514deb9665d Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 16 May 2017 15:03:39 +0200 Subject: Optimize lookups in the internalClass Inline the version taking an identifier, and use that one where it makes sense. Change-Id: I414c5999e61cdba219ecd1080957f3037dfebc1b Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4context.cpp | 22 +++++++++++++++++----- src/qml/jsruntime/qv4internalclass.cpp | 9 --------- src/qml/jsruntime/qv4internalclass_p.h | 9 ++++++++- src/qml/jsruntime/qv4object.cpp | 30 ++++++++++++++++++++++-------- 4 files changed, 47 insertions(+), 23 deletions(-) (limited to 'src/qml') diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index c4a0539750..03595aa59d 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -209,6 +209,9 @@ unsigned int CallContext::variableCount() const bool ExecutionContext::deleteProperty(String *name) { + name->makeIdentifier(engine()); + Identifier *id = name->identifier(); + Scope scope(this); bool hasWith = false; ScopedContext ctx(scope, this); @@ -237,7 +240,7 @@ bool ExecutionContext::deleteProperty(String *name) case Heap::ExecutionContext::Type_SimpleCallContext: { Heap::CallContext *c = static_cast(ctx->d()); if (c->v4Function && (c->v4Function->needsActivation() || hasWith)) { - uint index = c->v4Function->internalClass->find(name); + uint index = c->v4Function->internalClass->find(id); if (index < UINT_MAX) // ### throw in strict mode? return false; @@ -361,6 +364,9 @@ void QV4::ExecutionContext::simpleCall(Scope &scope, CallData *callData, Functio void ExecutionContext::setProperty(String *name, const Value &value) { + name->makeIdentifier(engine()); + Identifier *id = name->identifier(); + Scope scope(this); ScopedContext ctx(scope, this); ScopedObject activation(scope); @@ -392,7 +398,7 @@ void ExecutionContext::setProperty(String *name, const Value &value) case Heap::ExecutionContext::Type_SimpleCallContext: { Heap::CallContext *c = static_cast(ctx->d()); if (c->v4Function) { - uint index = c->v4Function->internalClass->find(name); + uint index = c->v4Function->internalClass->find(id); if (index < UINT_MAX) { if (index < c->v4Function->nFormals) { c->callData->args[c->v4Function->nFormals - index - 1] = value; @@ -414,7 +420,7 @@ void ExecutionContext::setProperty(String *name, const Value &value) } if (activation) { - uint member = activation->internalClass()->find(name); + uint member = activation->internalClass()->find(id); if (member < UINT_MAX) { activation->putValue(member, value); return; @@ -473,7 +479,10 @@ ReturnedValue ExecutionContext::getProperty(String *name) case Heap::ExecutionContext::Type_SimpleCallContext: { Heap::CallContext *c = static_cast(ctx->d()); if (c->v4Function && (c->v4Function->needsActivation() || hasWith || hasCatchScope)) { - uint index = c->v4Function->internalClass->find(name); + name->makeIdentifier(engine()); + Identifier *id = name->identifier(); + + uint index = c->v4Function->internalClass->find(id); if (index < UINT_MAX) { if (index < c->v4Function->nFormals) return c->callData->args[c->v4Function->nFormals - index - 1].asReturnedValue(); @@ -551,7 +560,10 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Value *base) case Heap::ExecutionContext::Type_SimpleCallContext: { Heap::CallContext *c = static_cast(ctx->d()); if (c->v4Function && (c->v4Function->needsActivation() || hasWith || hasCatchScope)) { - uint index = c->v4Function->internalClass->find(name); + name->makeIdentifier(engine()); + Identifier *id = name->identifier(); + + uint index = c->v4Function->internalClass->find(id); if (index < UINT_MAX) { if (index < c->v4Function->nFormals) return c->callData->args[c->v4Function->nFormals - index - 1].asReturnedValue(); diff --git a/src/qml/jsruntime/qv4internalclass.cpp b/src/qml/jsruntime/qv4internalclass.cpp index 600198567a..9f43871f27 100644 --- a/src/qml/jsruntime/qv4internalclass.cpp +++ b/src/qml/jsruntime/qv4internalclass.cpp @@ -429,15 +429,6 @@ uint QV4::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) diff --git a/src/qml/jsruntime/qv4internalclass_p.h b/src/qml/jsruntime/qv4internalclass_p.h index 031f66793b..34422098d9 100644 --- a/src/qml/jsruntime/qv4internalclass_p.h +++ b/src/qml/jsruntime/qv4internalclass_p.h @@ -279,7 +279,14 @@ struct InternalClass : public QQmlJS::Managed { static void changeMember(Object *object, String *string, PropertyAttributes data, uint *index = 0); static void removeMember(Object *object, Identifier *id); uint find(const String *string); - uint find(const Identifier *id); + uint find(const Identifier *id) + { + uint index = propertyTable.lookup(id); + if (index < size) + return index; + + return UINT_MAX; + } Q_REQUIRED_RESULT InternalClass *sealed(); Q_REQUIRED_RESULT InternalClass *frozen(); diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index c3ebb53622..cac9d8ad7d 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -294,7 +294,10 @@ void Object::getOwnProperty(String *name, PropertyAttributes *attrs, Property *p if (idx != UINT_MAX) return getOwnProperty(idx, attrs, p); - uint member = internalClass()->find(name); + name->makeIdentifier(engine()); + Identifier *id = name->identifier(); + + uint member = internalClass()->find(id); if (member < UINT_MAX) { *attrs = internalClass()->propertyData[member]; if (p) { @@ -336,9 +339,12 @@ Value *Object::getValueOrSetter(String *name, PropertyAttributes *attrs) { Q_ASSERT(name->asArrayIndex() == UINT_MAX); + name->makeIdentifier(engine()); + Identifier *id = name->identifier(); + Heap::Object *o = d(); while (o) { - uint idx = o->internalClass->find(name); + uint idx = o->internalClass->find(id); if (idx < UINT_MAX) { *attrs = o->internalClass->propertyData[idx]; return o->propertyData(attrs->isAccessor() ? idx + SetterOffset : idx); @@ -411,7 +417,10 @@ bool Object::hasOwnProperty(String *name) const if (idx != UINT_MAX) return hasOwnProperty(idx); - if (internalClass()->find(name) < UINT_MAX) + name->makeIdentifier(engine()); + Identifier *id = name->identifier(); + + if (internalClass()->find(id) < UINT_MAX) return true; if (!query(name).isEmpty()) return true; @@ -468,8 +477,11 @@ PropertyAttributes Object::query(const Managed *m, String *name) if (idx != UINT_MAX) return queryIndexed(m, idx); + name->makeIdentifier(m->internalClass()->engine); + Identifier *id = name->identifier(); + const Object *o = static_cast(m); - idx = o->internalClass()->find(name); + idx = o->internalClass()->find(id); if (idx < UINT_MAX) return o->internalClass()->propertyData[idx]; @@ -670,10 +682,11 @@ ReturnedValue Object::internalGet(String *name, bool *hasProperty) const Scope scope(engine()); name->makeIdentifier(scope.engine); + Identifier *id = name->identifier(); ScopedObject o(scope, this); while (o) { - uint idx = o->internalClass()->find(name); + uint idx = o->internalClass()->find(id); if (idx < UINT_MAX) { if (hasProperty) *hasProperty = true; @@ -736,8 +749,9 @@ void Object::internalPut(String *name, const Value &value) return putIndexed(idx, value); name->makeIdentifier(engine()); + Identifier *id = name->identifier(); - uint member = internalClass()->find(name); + uint member = internalClass()->find(id); Value *v = 0; PropertyAttributes attrs; if (member < UINT_MAX) { @@ -890,7 +904,7 @@ bool Object::internalDeleteProperty(String *name) name->makeIdentifier(engine()); - uint memberIdx = internalClass()->find(name); + uint memberIdx = internalClass()->find(name->identifier()); if (memberIdx != UINT_MAX) { if (internalClass()->propertyData[memberIdx].isConfigurable()) { InternalClass::removeMember(this, name->identifier()); @@ -961,7 +975,7 @@ bool Object::__defineOwnProperty__(ExecutionEngine *engine, String *name, const } // Clause 1 - memberIndex = internalClass()->find(name); + memberIndex = internalClass()->find(name->identifier()); if (memberIndex == UINT_MAX) { // clause 3 -- cgit v1.2.3