diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-02-14 16:35:12 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-16 17:57:02 +0100 |
commit | 037ac0f08e9365ecf58af52749f262de50d97752 (patch) | |
tree | aef4785cbfe0f64bf263d20b61f6a6913365a059 /src/qml/qml/v8/qv8engine.cpp | |
parent | 2f3f19e6f7e0a2f635762a4ee053020c2237ad30 (diff) |
Reduce memory usage for object literals with integral keys
Be more aggressive about using sparse arrays for object literals than for
regular array handling, to reduce the memory usage in this use case. The
current heuristic is that indices over 0x1000 switch to sparse, which means a
simple { "3000" : "test" } creates a long vector instead of a sparse array.
Task-number: QTBUG-36803
Change-Id: Id05c76f0f597cd016114cd27ec54effbebe26e48
Reviewed-by: Michael Brasser <michael.brasser@live.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/qml/v8/qv8engine.cpp')
-rw-r--r-- | src/qml/qml/v8/qv8engine.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 76327e3a69..f448cca439 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -226,8 +226,13 @@ static QV4::ReturnedValue objectFromVariantMap(QV8Engine *engine, const QVariant QV4::ScopedObject o(scope, e->newObject()); QV4::ScopedString s(scope); QV4::ScopedValue v(scope); - for (QVariantMap::ConstIterator iter = map.begin(); iter != map.end(); ++iter) - o->put((s = e->newString(iter.key())), (v = engine->fromVariant(iter.value()))); + for (QVariantMap::ConstIterator iter = map.begin(); iter != map.end(); ++iter) { + s = e->newString(iter.key()); + uint idx = s->asArrayIndex(); + if (idx > 16 && (!o->arrayData || idx > o->arrayData->length() * 2)) + o->initSparseArray(); + o->put(s, (v = engine->fromVariant(iter.value()))); + } return o.asReturnedValue(); } |