From a62955472b2acd644db46ea194d4fb0bc119150f Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 15 Jun 2014 08:12:17 +0200 Subject: v4: Delay creating the ScopedValue/ScopedProperty in objectLiteral Creating a ScopedValue/ScopedProperty is not free. It will use the ExecutionEngine directly to reserve memory from the JS Stack. In tests/manual/v4/v8-bench.js and bench-allocate-nonretained.js a lot of objects are created and the arrayValueCount and the arrayGetterSetterCount are 0. We can delay the creation for a small gain. When generating the code we already know the various sizes and could already call specialized versions of the creation code. The gain is not so clear though. Change-Id: Ic99b241f5506457e57611ad4eba143c56be1f657 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4runtime.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index e44d1a07a6..bd52f0e678 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -1162,24 +1162,28 @@ ReturnedValue Runtime::objectLiteral(QV4::ExecutionContext *ctx, const QV4::Valu for (uint i = 0; i < klass->size; ++i) o->memberData[i] = *args++; - ScopedValue entry(scope); - for (int i = 0; i < arrayValueCount; ++i) { - uint idx = args->toUInt32(); - ++args; - entry = *args++; - o->arraySet(idx, entry); + if (arrayValueCount > 0) { + ScopedValue entry(scope); + for (int i = 0; i < arrayValueCount; ++i) { + uint idx = args->toUInt32(); + ++args; + entry = *args++; + o->arraySet(idx, entry); + } } - ScopedProperty pd(scope); uint arrayGetterSetterCount = arrayGetterSetterCountAndFlags & ((1 << 30) - 1); - for (uint i = 0; i < arrayGetterSetterCount; ++i) { - uint idx = args->toUInt32(); - ++args; - pd->value = *args; - ++args; - pd->set = *args; - ++args; - o->arraySet(idx, pd, Attr_Accessor); + if (arrayGetterSetterCount > 0) { + ScopedProperty pd(scope); + for (uint i = 0; i < arrayGetterSetterCount; ++i) { + uint idx = args->toUInt32(); + ++args; + pd->value = *args; + ++args; + pd->set = *args; + ++args; + o->arraySet(idx, pd, Attr_Accessor); + } } return o.asReturnedValue(); -- cgit v1.2.3