diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-04-09 15:50:55 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-04-16 17:14:09 +0000 |
commit | d22db9e458828d403110fa0b9de1ca0c831d7e96 (patch) | |
tree | ab696dd88d47ec47febe4278ebad83ad43c5015d /src | |
parent | 63877c930e8efa119ac16798ed546cdba68f818b (diff) |
Speed up script binding initialization
Don't spend any time repeatedly building the same internal class for the simple
binding functions. We can do that once at engine construction time.
Change-Id: I3777b5bd15ad4a8aaf78ae13bee27e8d8cadc2ee
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine_p.h | 1 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4functionobject.cpp | 18 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4functionobject_p.h | 4 |
4 files changed, 21 insertions, 6 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index dfc7745f56..cbfac86e9f 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -308,6 +308,10 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) functionPrototype = memoryManager->alloc<FunctionPrototype>(functionProtoClass, objectPrototype.asObject()); functionClass = emptyClass->addMember(id_prototype, Attr_NotEnumerable|Attr_NotConfigurable, &index); Q_ASSERT(index == Heap::FunctionObject::Index_Prototype); + simpleScriptFunctionClass = functionClass->addMember(id_name, Attr_ReadOnly, &index); + Q_ASSERT(index == Heap::SimpleScriptFunction::Index_Name); + simpleScriptFunctionClass = simpleScriptFunctionClass->addMember(id_length, Attr_ReadOnly, &index); + Q_ASSERT(index == Heap::SimpleScriptFunction::Index_Length); protoClass = emptyClass->addMember(id_constructor, Attr_NotEnumerable, &index); Q_ASSERT(index == Heap::FunctionObject::Index_ProtoConstructor); diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index bcb74ab694..f01579be71 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -169,6 +169,7 @@ public: InternalClass *arrayClass; InternalClass *functionClass; + InternalClass *simpleScriptFunctionClass; InternalClass *protoClass; InternalClass *regExpExecArrayClass; diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index f7433e6365..7006a8892d 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -459,21 +459,27 @@ ReturnedValue ScriptFunction::call(Managed *that, CallData *callData) DEFINE_OBJECT_VTABLE(SimpleScriptFunction); Heap::SimpleScriptFunction::SimpleScriptFunction(QV4::ExecutionContext *scope, Function *function, bool createProto) - : Heap::FunctionObject(scope, function, createProto) + : Heap::FunctionObject(function->compilationUnit->engine->simpleScriptFunctionClass, function->compilationUnit->engine->functionPrototype.asObject()) { + this->scope = scope->d(); + this->function = function; function->compilationUnit->addref(); Q_ASSERT(function); Q_ASSERT(function->code); - // global function - if (!scope) - return; - Scope s(scope); ScopedFunctionObject f(s, this); - f->defineReadonlyProperty(scope->d()->engine->id_length, Primitive::fromInt32(f->formalParameterCount())); + if (createProto) { + ScopedString name(s, function->name()); + f->init(name, createProto); + f->defineReadonlyProperty(scope->d()->engine->id_length, Primitive::fromInt32(f->formalParameterCount())); + } else { + f->ensureMemberIndex(s.engine, Index_Length); + memberData->data[Index_Name] = function->name(); + memberData->data[Index_Length] = Primitive::fromInt32(f->formalParameterCount()); + } if (scope->d()->strictMode) { ScopedProperty pd(s); diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h index 560061a705..252ff40a1a 100644 --- a/src/qml/jsruntime/qv4functionobject_p.h +++ b/src/qml/jsruntime/qv4functionobject_p.h @@ -89,6 +89,10 @@ struct IndexedBuiltinFunction : FunctionObject { }; struct SimpleScriptFunction : FunctionObject { + enum { + Index_Name = FunctionObject::Index_Prototype + 1, + Index_Length + }; SimpleScriptFunction(QV4::ExecutionContext *scope, Function *function, bool createProto); }; |