diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-01-14 16:22:33 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2015-01-21 18:22:52 +0100 |
commit | 8209f35b7961b7ea6867d7ebfb5288dcf40ecd71 (patch) | |
tree | f9e8b5083788574b75d7dba7f4ca1c60eded86fe /src/qml/jsapi/qjsvalueiterator.cpp | |
parent | d8131513b07d3f0a6d749c9961b294fc955fed6d (diff) |
Rework QJSValue internals
Use a flagged pointer to either store a pointer to a
QV4::Value (from the persistent storage) or a pointer to
a QVariant in QJSValue::d. Like this we don't need to malloc
to create a QJSValue for most use cases.
Significantly reduces the memory consumption of QJSValue and
speeds it up a lot.
Change-Id: I10902cc4b6cc3f43d3f816875dc6c4bbb6b4490f
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsapi/qjsvalueiterator.cpp')
-rw-r--r-- | src/qml/jsapi/qjsvalueiterator.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/qml/jsapi/qjsvalueiterator.cpp b/src/qml/jsapi/qjsvalueiterator.cpp index 2b27f655c8..6f78f71f48 100644 --- a/src/qml/jsapi/qjsvalueiterator.cpp +++ b/src/qml/jsapi/qjsvalueiterator.cpp @@ -45,13 +45,12 @@ QJSValueIteratorPrivate::QJSValueIteratorPrivate(const QJSValue &v) , currentIndex(UINT_MAX) , nextIndex(UINT_MAX) { - QJSValuePrivate *jsp = QJSValuePrivate::get(value); - QV4::ExecutionEngine *e = jsp->persistent.engine(); + QV4::ExecutionEngine *e = QJSValuePrivate::engine(&v); if (!e) return; QV4::Scope scope(e); - QV4::ScopedObject o(scope, jsp->persistent.value()); + QV4::ScopedObject o(scope, QJSValuePrivate::getValue(&v)); iterator.set(e, e->newForEachIteratorObject(o)); currentName = (QV4::String *)0; @@ -123,7 +122,7 @@ QJSValueIterator::~QJSValueIterator() */ bool QJSValueIterator::hasNext() const { - QV4::Value *val = QJSValuePrivate::get(d_ptr->value)->persistent.valueRef(); + QV4::Value *val = QJSValuePrivate::getValue(&d_ptr->value); if (!val || !val->isObject()) return false; return !!d_ptr->nextName || d_ptr->nextIndex != UINT_MAX; @@ -139,7 +138,7 @@ bool QJSValueIterator::hasNext() const */ bool QJSValueIterator::next() { - QV4::Value *val = QJSValuePrivate::get(d_ptr->value)->persistent.valueRef(); + QV4::Value *val = QJSValuePrivate::getValue(&d_ptr->value); if (!val || !val->isObject()) return false; d_ptr->currentName = d_ptr->nextName; @@ -166,7 +165,7 @@ bool QJSValueIterator::next() */ QString QJSValueIterator::name() const { - QV4::Value *val = QJSValuePrivate::get(d_ptr->value)->persistent.valueRef(); + QV4::Value *val = QJSValuePrivate::getValue(&d_ptr->value); if (!val || !val->isObject()) return QString(); if (!!d_ptr->currentName) @@ -189,7 +188,7 @@ QJSValue QJSValueIterator::value() const if (!engine) return QJSValue(); QV4::Scope scope(engine); - QV4::ScopedObject obj(scope, QJSValuePrivate::get(d_ptr->value)->persistent.value()); + QV4::ScopedObject obj(scope, QJSValuePrivate::getValue(&d_ptr->value)); if (!obj) return QJSValue(); @@ -223,9 +222,8 @@ QJSValueIterator& QJSValueIterator::operator=(QJSValue& object) return *this; } - QJSValuePrivate *jsp = QJSValuePrivate::get(object); QV4::Scope scope(v4); - QV4::ScopedObject o(scope, jsp->persistent.value()); + QV4::ScopedObject o(scope, QJSValuePrivate::getValue(&object)); d_ptr->iterator.set(v4, v4->newForEachIteratorObject(o)); QV4::Scoped<QV4::ForEachIteratorObject> it(scope, d_ptr->iterator.value()); it->d()->it.flags = QV4::ObjectIterator::NoFlags; |