Speed up creation of Array literals

Gives around 10% speedup on the v8 splay benchmark.

Change-Id: I47f64e7b73bde59ac3bdd2c94fc199ecfbbf290e
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
This commit is contained in:
Lars Knoll 2015-09-08 14:58:16 +02:00
parent 3f12ee31a4
commit c72f973a35
3 changed files with 22 additions and 9 deletions

View File

@ -618,6 +618,26 @@ Heap::ArrayObject *ExecutionEngine::newArrayObject(int count)
return object->d();
}
Heap::ArrayObject *ExecutionEngine::newArrayObject(const Value *values, int length)
{
Scope scope(this);
ScopedArrayObject a(scope, memoryManager->allocObject<ArrayObject>());
if (length) {
size_t size = sizeof(Heap::ArrayData) + (length-1)*sizeof(Value);
Heap::SimpleArrayData *d = scope.engine->memoryManager->allocManaged<SimpleArrayData>(size);
new (d) Heap::SimpleArrayData;
d->alloc = length;
d->type = Heap::ArrayData::Simple;
d->offset = 0;
d->len = length;
memcpy(&d->arrayData, values, length*sizeof(Value));
a->d()->arrayData = d;
a->setArrayLengthUnchecked(length);
}
return a->d();
}
Heap::ArrayObject *ExecutionEngine::newArrayObject(const QStringList &list)
{
Scope scope(this);

View File

@ -373,6 +373,7 @@ public:
Heap::Object *newBooleanObject(bool b);
Heap::ArrayObject *newArrayObject(int count = 0);
Heap::ArrayObject *newArrayObject(const Value *values, int length);
Heap::ArrayObject *newArrayObject(const QStringList &list);
Heap::ArrayObject *newArrayObject(InternalClass *ic, Object *prototype);

View File

@ -1209,15 +1209,7 @@ void Runtime::declareVar(ExecutionEngine *engine, bool deletable, int nameIndex)
ReturnedValue Runtime::arrayLiteral(ExecutionEngine *engine, Value *values, uint length)
{
Scope scope(engine);
ScopedArrayObject a(scope, engine->newArrayObject());
if (length) {
a->arrayReserve(length);
a->arrayPut(0, values, length);
a->setArrayLengthUnchecked(length);
}
return a.asReturnedValue();
return engine->newArrayObject(values, length)->asReturnedValue();
}
ReturnedValue Runtime::objectLiteral(ExecutionEngine *engine, const QV4::Value *args, int classId, int arrayValueCount, int arrayGetterSetterCountAndFlags)