From 6359ab63cd9c730a168e8b8da4c275e2d03d25d5 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sun, 1 Sep 2013 21:22:57 +0200 Subject: Optimize ScriptFunction::construct() and creation of FunctionObjects Change-Id: I7df04171a26cbe659e85f14878cc4e51030e8a5a Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4functionobject.cpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'src/qml/jsruntime/qv4functionobject.cpp') diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 26587bd91b..934973168d 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -69,8 +69,8 @@ using namespace QV4; DEFINE_MANAGED_VTABLE(FunctionObject); -FunctionObject::FunctionObject(ExecutionContext *scope, String *name) - : Object(scope->engine->functionClass) +FunctionObject::FunctionObject(ExecutionContext *scope, String *name, bool createProto) + : Object(createProto ? scope->engine->functionWithProtoClass : scope->engine->functionClass) , scope(scope) , name(name) , formalParameterList(0) @@ -89,6 +89,12 @@ FunctionObject::FunctionObject(ExecutionContext *scope, String *name) assert(scope->next != (ExecutionContext *)0x1); #endif + if (createProto) { + Object *proto = scope->engine->newObject(scope->engine->protoClass); + proto->memberData[Index_ProtoConstructor].value = Value::fromObject(this); + memberData[Index_Prototype].value = Value::fromObject(proto); + } + if (name) defineReadonlyProperty(scope->engine->id_name, Value::fromString(name)); } @@ -358,7 +364,7 @@ static Value throwTypeError(SimpleCallContext *ctx) DEFINE_MANAGED_VTABLE(ScriptFunction); ScriptFunction::ScriptFunction(ExecutionContext *scope, Function *function) - : FunctionObject(scope, function->name) + : FunctionObject(scope, function->name, true) { vtbl = &static_vtbl; this->function = function; @@ -382,11 +388,6 @@ ScriptFunction::ScriptFunction(ExecutionContext *scope, Function *function) varCount = function->locals.size(); varList = function->locals.constData(); - Object *proto = scope->engine->newObject(); - proto->defineDefaultProperty(scope->engine->id_constructor, Value::fromObject(this)); - Property *pd = insertMember(scope->engine->id_prototype, Attr_NotEnumerable|Attr_NotConfigurable); - pd->value = Value::fromObject(proto); - if (scope->strictMode) { FunctionObject *thrower = scope->engine->newBuiltinFunction(scope, 0, throwTypeError); Property pd = Property::fromAccessor(thrower, thrower); @@ -401,7 +402,7 @@ Value ScriptFunction::construct(Managed *that, const CallData &d) ExecutionEngine *v4 = f->engine(); InternalClass *ic = v4->objectClass; - Value proto = f->get(v4->id_prototype); + Value proto = f->memberData[Index_Prototype].value; if (proto.isObject()) ic = v4->emptyClass->changePrototype(proto.objectValue()); Object *obj = v4->newObject(ic); @@ -454,7 +455,7 @@ Value ScriptFunction::call(Managed *that, const CallData &d) DEFINE_MANAGED_VTABLE(SimpleScriptFunction); SimpleScriptFunction::SimpleScriptFunction(ExecutionContext *scope, Function *function) - : FunctionObject(scope, function->name) + : FunctionObject(scope, function->name, true) { vtbl = &static_vtbl; this->function = function; @@ -478,11 +479,6 @@ SimpleScriptFunction::SimpleScriptFunction(ExecutionContext *scope, Function *fu varCount = function->locals.size(); varList = function->locals.constData(); - Object *proto = scope->engine->newObject(); - proto->defineDefaultProperty(scope->engine->id_constructor, Value::fromObject(this)); - Property *pd = insertMember(scope->engine->id_prototype, Attr_NotEnumerable|Attr_NotConfigurable); - pd->value = Value::fromObject(proto); - if (scope->strictMode) { FunctionObject *thrower = scope->engine->newBuiltinFunction(scope, 0, throwTypeError); Property pd = Property::fromAccessor(thrower, thrower); @@ -497,7 +493,7 @@ Value SimpleScriptFunction::construct(Managed *that, const CallData &d) ExecutionEngine *v4 = f->engine(); InternalClass *ic = v4->objectClass; - Value proto = f->get(v4->id_prototype); + Value proto = f->memberData[Index_Prototype].value; if (proto.isObject()) ic = v4->emptyClass->changePrototype(proto.objectValue()); Object *obj = v4->newObject(ic); -- cgit v1.2.3