From c72f973a35c0ba0a70a00f5c4d6bed8b0edbc21d Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 8 Sep 2015 14:58:16 +0200 Subject: Speed up creation of Array literals Gives around 10% speedup on the v8 splay benchmark. Change-Id: I47f64e7b73bde59ac3bdd2c94fc199ecfbbf290e Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4engine.cpp | 20 ++++++++++++++++++++ src/qml/jsruntime/qv4engine_p.h | 1 + src/qml/jsruntime/qv4runtime.cpp | 10 +--------- 3 files changed, 22 insertions(+), 9 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index e306106aea..d5a47273a9 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -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()); + + if (length) { + size_t size = sizeof(Heap::ArrayData) + (length-1)*sizeof(Value); + Heap::SimpleArrayData *d = scope.engine->memoryManager->allocManaged(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); diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index 447105c2ab..ef9d83cea3 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -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); diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index d122f06d05..0d7a1851b8 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -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) -- cgit v1.2.3