From bf6191f090b326eb0776cd4e921ddb56c8daa8a9 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 13 Jan 2014 09:09:14 +0100 Subject: Add a SimpleArrayData class This makes the ArrayData class 'pure virtual'. SimpleArrayData now contains the implementation of simple arrays. This makes the separation between simple and sparse arrays a lot cleaner. It also allows us to move len and offset from the base class into the SimpleArrayClass. This fixes some bugs where we accessed len for sparse arrays leading to some buggy behavior. Added a virtual length() method to ArrayData to query the highes used index in the Array. Change-Id: Iab2ba2a48ebe5b7031759eeb4ebe02b4d86233f0 Reviewed-by: Simon Hausmann --- src/qml/qml/v8/qv8engine.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/qml/qml/v8/qv8engine.cpp') diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index aa3b7eeb34..35fc5315d5 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -197,10 +197,9 @@ static QV4::ReturnedValue arrayFromStringList(QV8Engine *engine, const QStringLi int len = list.count(); a->arrayReserve(len); QV4::ScopedValue v(scope); - for (int ii = 0; ii < len; ++ii) { + for (int ii = 0; ii < len; ++ii) a->arrayData->put(ii, (v = QV4::Encode(e->newString(list.at(ii))))); - a->arrayData->setLength(ii + 1); - } + a->setArrayLengthUnchecked(len); return a.asReturnedValue(); } @@ -213,10 +212,9 @@ static QV4::ReturnedValue arrayFromVariantList(QV8Engine *engine, const QVariant int len = list.count(); a->arrayReserve(len); QV4::ScopedValue v(scope); - for (int ii = 0; ii < len; ++ii) { + for (int ii = 0; ii < len; ++ii) a->arrayData->put(ii, (v = engine->fromVariant(list.at(ii)))); - a->arrayData->setLength(ii + 1); - } + a->setArrayLengthUnchecked(len); return a.asReturnedValue(); } @@ -329,10 +327,8 @@ QV4::ReturnedValue QV8Engine::fromVariant(const QVariant &variant) QV4::Scoped a(scope, m_v4Engine->newArrayObject()); a->arrayReserve(list.count()); QV4::ScopedValue v(scope); - for (int ii = 0; ii < list.count(); ++ii) { + for (int ii = 0; ii < list.count(); ++ii) a->arrayData->put(ii, (v = QV4::QObjectWrapper::wrap(m_v4Engine, list.at(ii)))); - a->arrayData->setLength(ii + 1); - } a->setArrayLengthUnchecked(list.count()); return a.asReturnedValue(); } else if (QMetaType::typeFlags(type) & QMetaType::PointerToQObject) { @@ -547,10 +543,8 @@ QV4::ReturnedValue QV8Engine::variantListToJS(const QVariantList &lst) QV4::Scoped a(scope, m_v4Engine->newArrayObject()); a->arrayReserve(lst.size()); QV4::ScopedValue v(scope); - for (int i = 0; i < lst.size(); i++) { + for (int i = 0; i < lst.size(); i++) a->arrayData->put(i, (v = variantToJS(lst.at(i)))); - a->arrayData->setLength(i + 1); - } a->setArrayLengthUnchecked(lst.size()); return a.asReturnedValue(); } -- cgit v1.2.3