summaryrefslogtreecommitdiff
path: root/src/qml/jsruntime/qv4functionobject.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-11-14 22:08:00 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-12-04 09:45:25 +0100
commit8e25658011699596996e80d3d08f17ef2efa0634 (patch)
tree1b8322bd409e274c837e20dc64187fff3431fef2 /src/qml/jsruntime/qv4functionobject.cpp
parent0e864f2814959b0861ea5b07108893c2c4a047c6 (diff)
downloadqtdeclarative-8e25658011699596996e80d3d08f17ef2efa0634.tar.gz
Speedup JS instanceof operator
Cache the prototype of the functionobject, and inline hasInstance. This removes a vtbl method and speeds things up quite a bit. Change-Id: Ic68f301f7e09763d445a98bffa2cd201303f902e Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4functionobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp51
1 files changed, 18 insertions, 33 deletions
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 037f06cd35..32ef98327b 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -81,6 +81,8 @@ FunctionObject::FunctionObject(ExecutionContext *scope, const StringRef name, bo
, formalParameterCount(0)
, varCount(0)
, function(0)
+ , protoCacheClass(0)
+ , protoCacheIndex(UINT_MAX)
{
init(name, createProto);
}
@@ -93,6 +95,8 @@ FunctionObject::FunctionObject(ExecutionContext *scope, const QString &name, boo
, formalParameterCount(0)
, varCount(0)
, function(0)
+ , protoCacheClass(0)
+ , protoCacheIndex(UINT_MAX)
{
// set the name to something here, so that a gc run a few lines below doesn't crash on it
this->name = scope->engine->id_undefined;
@@ -158,33 +162,6 @@ ReturnedValue FunctionObject::newInstance()
return construct(callData);
}
-bool FunctionObject::hasInstance(Managed *that, const ValueRef value)
-{
- Scope scope(that->internalClass->engine);
- ScopedFunctionObject f(scope, static_cast<FunctionObject *>(that));
-
- ScopedObject v(scope, value);
- if (!v)
- return false;
-
- Scoped<Object> o(scope, f->get(scope.engine->id_prototype));
- if (!o) {
- scope.engine->current->throwTypeError();
- return false;
- }
-
- while (v) {
- v = v->prototype();
-
- if (! v)
- break;
- else if (o.getPointer() == v)
- return true;
- }
-
- return false;
-}
-
ReturnedValue FunctionObject::construct(Managed *that, CallData *)
{
ExecutionEngine *v4 = that->internalClass->engine;
@@ -231,6 +208,19 @@ FunctionObject *FunctionObject::creatScriptFunction(ExecutionContext *scope, Fun
return new (scope->engine->memoryManager) SimpleScriptFunction(scope, function);
}
+ReturnedValue FunctionObject::protoProperty()
+{
+ if (protoCacheClass != internalClass) {
+ protoCacheClass = internalClass;
+ protoCacheIndex = internalClass->find(internalClass->engine->id_prototype);
+ }
+ if (protoCacheIndex < UINT_MAX) {
+ if (internalClass->propertyData.at(protoCacheIndex).isData())
+ return memberData[protoCacheIndex].value.asReturnedValue();
+ }
+ return get(internalClass->engine->id_prototype);
+}
+
DEFINE_MANAGED_VTABLE(FunctionCtor);
@@ -667,6 +657,7 @@ BoundFunction::BoundFunction(ExecutionContext *scope, FunctionObjectRef target,
, boundArgs(boundArgs)
{
vtbl = &static_vtbl;
+ subtype = FunctionObject::BoundFunction;
this->boundThis = boundThis;
Scope s(scope);
@@ -718,12 +709,6 @@ ReturnedValue BoundFunction::construct(Managed *that, CallData *dd)
return f->target->construct(callData);
}
-bool BoundFunction::hasInstance(Managed *that, const ValueRef value)
-{
- BoundFunction *f = static_cast<BoundFunction *>(that);
- return FunctionObject::hasInstance(f->target, value);
-}
-
void BoundFunction::markObjects(Managed *that, ExecutionEngine *e)
{
BoundFunction *o = static_cast<BoundFunction *>(that);