Optimize code in instanceOf() of FunctionObject::protoForConstructor()

Saves around 1.5% instructions for the Earley Boyer benchmark

Change-Id: I552d324d5e1713f655ab9909f30c9527bb4ff777
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Lars Knoll 2016-12-12 10:49:55 +01:00
parent 4ccba8ea25
commit 180decaf11
3 changed files with 17 additions and 17 deletions

View File

@ -451,11 +451,10 @@ void Heap::ScriptFunction::init(QV4::ExecutionContext *scope, Function *function
Heap::Object *ScriptFunction::protoForConstructor() const Heap::Object *ScriptFunction::protoForConstructor() const
{ {
Scope scope(engine()); const Object *o = d()->protoProperty();
ScopedObject p(scope, protoProperty()); if (o)
if (p) return o->d();
return p->d(); return engine()->objectPrototype()->d();
return scope.engine->objectPrototype()->d();
} }

View File

@ -79,6 +79,8 @@ struct Q_QML_PRIVATE_EXPORT FunctionObject : Object {
unsigned int varCount() { return function ? function->compiledFunction->nLocals : 0; } unsigned int varCount() { return function ? function->compiledFunction->nLocals : 0; }
bool needsActivation() const { return function ? function->needsActivation() : false; } bool needsActivation() const { return function ? function->needsActivation() : false; }
const QV4::Object *protoProperty() const { return propertyData(Index_Prototype)->cast<QV4::Object>(); }
Pointer<ExecutionContext> scope; Pointer<ExecutionContext> scope;
Function *function; Function *function;
}; };
@ -145,8 +147,6 @@ struct Q_QML_EXPORT FunctionObject: Object {
static Heap::FunctionObject *createScriptFunction(ExecutionContext *scope, Function *function); static Heap::FunctionObject *createScriptFunction(ExecutionContext *scope, Function *function);
ReturnedValue protoProperty() const { return propertyData(Heap::FunctionObject::Index_Prototype)->asReturnedValue(); }
bool needsActivation() const { return d()->needsActivation(); } bool needsActivation() const { return d()->needsActivation(); }
bool strictMode() const { return d()->function ? d()->function->isStrict() : false; } bool strictMode() const { return d()->function ? d()->function->isStrict() : false; }
bool isBinding() const; bool isBinding() const;

View File

@ -345,28 +345,29 @@ ReturnedValue Runtime::method_deleteName(ExecutionEngine *engine, int nameIndex)
QV4::ReturnedValue Runtime::method_instanceof(ExecutionEngine *engine, const Value &left, const Value &right) QV4::ReturnedValue Runtime::method_instanceof(ExecutionEngine *engine, const Value &left, const Value &right)
{ {
Scope scope(engine); const FunctionObject *function = right.as<FunctionObject>();
ScopedFunctionObject f(scope, right.as<FunctionObject>()); if (!function)
if (!f)
return engine->throwTypeError(); return engine->throwTypeError();
if (f->isBoundFunction()) Heap::FunctionObject *f = function->d();
f = static_cast<BoundFunction *>(f.getPointer())->target(); if (function->isBoundFunction())
f = function->cast<BoundFunction>()->target();
ScopedObject v(scope, left.as<Object>()); const Object *o = left.as<Object>();
if (!v) if (!o)
return Encode(false); return Encode(false);
Heap::Object *v = o->d();
ScopedObject o(scope, f->protoProperty()); o = f->protoProperty();
if (!o) if (!o)
return engine->throwTypeError(); return engine->throwTypeError();
while (v) { while (v) {
v = v->prototype(); v = v->prototype;
if (!v) if (!v)
break; break;
else if (o->d() == v->d()) else if (o->d() == v)
return Encode(true); return Encode(true);
} }