aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-02-14 16:35:12 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-16 17:57:02 +0100
commit037ac0f08e9365ecf58af52749f262de50d97752 (patch)
treeaef4785cbfe0f64bf263d20b61f6a6913365a059
parent2f3f19e6f7e0a2f635762a4ee053020c2237ad30 (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>
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp2
-rw-r--r--src/qml/qml/v8/qv8engine.cpp9
2 files changed, 9 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index a3cae3382d..38d46f3eea 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -1095,6 +1095,8 @@ void __qmljs_builtin_define_property(ExecutionContext *ctx, const ValueRef objec
uint idx = name->asArrayIndex();
if (idx != UINT_MAX) {
+ if (idx > 16 && (!o->arrayData || idx > o->arrayData->length() * 2))
+ o->initSparseArray();
o->arraySet(idx, val);
} else {
ScopedValue v(scope, val ? *val : Primitive::undefinedValue());
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();
}