diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2018-11-20 11:03:46 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2018-11-22 08:51:59 +0000 |
commit | 9926a4a49e8211a996667b467fd98b915e9f9d34 (patch) | |
tree | d514b131de6da988bc39c40753d2298b0cdccb09 /src/qml/jsruntime/qv4qobjectwrapper_p.h | |
parent | 33c13efd91954fb50019e82f3ab8e8e1d8458332 (diff) |
V4: Avoid copying WeakValues with wrapped QObjects
Such WeakValues are kept alive until the respective QObject is deleted.
Therefore they are quite expensive. In this case we don't actually need
a copy as on retrieval we only want a ReturnValue and on inserting we
just want to replace the value in the map.
Fixes: QTBUG-71817
Change-Id: I385c55140337d468289046243941077ba1ff61a3
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4qobjectwrapper_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper_p.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h index be46245d5a..6465ee0fa6 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper_p.h +++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h @@ -290,7 +290,14 @@ public: Iterator end() { return QHash<QObject*, QV4::WeakValue>::end(); } void insert(QObject *key, Heap::Object *value); - ReturnedValue value(QObject *key) const { return QHash<QObject*, QV4::WeakValue>::value(key).value(); } + ReturnedValue value(QObject *key) const + { + ConstIterator it = find(key); + return it == end() + ? QV4::WeakValue().value() + : it->value(); + } + Iterator erase(Iterator it); void remove(QObject *key); void mark(QObject *key, MarkStack *markStack); |