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
{
Scope scope(engine());
ScopedObject p(scope, protoProperty());
if (p)
return p->d();
return scope.engine->objectPrototype()->d();
const Object *o = d()->protoProperty();
if (o)
return o->d();
return 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; }
bool needsActivation() const { return function ? function->needsActivation() : false; }
const QV4::Object *protoProperty() const { return propertyData(Index_Prototype)->cast<QV4::Object>(); }
Pointer<ExecutionContext> scope;
Function *function;
};
@ -145,8 +147,6 @@ struct Q_QML_EXPORT FunctionObject: Object {
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 strictMode() const { return d()->function ? d()->function->isStrict() : false; }
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)
{
Scope scope(engine);
ScopedFunctionObject f(scope, right.as<FunctionObject>());
if (!f)
const FunctionObject *function = right.as<FunctionObject>();
if (!function)
return engine->throwTypeError();
if (f->isBoundFunction())
f = static_cast<BoundFunction *>(f.getPointer())->target();
Heap::FunctionObject *f = function->d();
if (function->isBoundFunction())
f = function->cast<BoundFunction>()->target();
ScopedObject v(scope, left.as<Object>());
if (!v)
const Object *o = left.as<Object>();
if (!o)
return Encode(false);
Heap::Object *v = o->d();
ScopedObject o(scope, f->protoProperty());
o = f->protoProperty();
if (!o)
return engine->throwTypeError();
while (v) {
v = v->prototype();
v = v->prototype;
if (!v)
break;
else if (o->d() == v->d())
else if (o->d() == v)
return Encode(true);
}