diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-04-05 12:30:36 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-04-05 22:58:06 +0200 |
commit | 5bab4d8adedb2d16651685845bcf2dc4133be9d7 (patch) | |
tree | e7a9df7697d46cc0979abec4df3a4eb2866ae93c /src/qml/qml/qqmlpropertycache_p.h | |
parent | 35678b086e6083a83cca65a973b35c985d44b133 (diff) |
QQmlMetaObjectPointer: optimize atomic operations [2/2]: acquires /= 2
In the destructor, as well as in the metaObject() method, the old code
used the implicit conversion from QAtomic<T> to T, which is equivalent
to load-acquire. The code performed up to two reads each, which means
two load-acquire operations where one suffices.
Cache the result of the loadAcquire() and perform further operations
on the cached value instead of the atomic variable.
Found by locally disabling QAtomic<T> -> T implicit conversion
operators.
Change-Id: I6a4ceaf462714eaad8c79fc4f26a9521525ee1c7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/qml/qml/qqmlpropertycache_p.h')
-rw-r--r-- | src/qml/qml/qqmlpropertycache_p.h | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/qml/qml/qqmlpropertycache_p.h b/src/qml/qml/qqmlpropertycache_p.h index 7f3fc5f4fc..e6a08f33c7 100644 --- a/src/qml/qml/qqmlpropertycache_p.h +++ b/src/qml/qml/qqmlpropertycache_p.h @@ -85,8 +85,9 @@ public: ~QQmlMetaObjectPointer() { - if (d & Shared) - reinterpret_cast<SharedHolder *>(d ^ Shared)->release(); + const auto dd = d.loadAcquire(); + if (dd & Shared) + reinterpret_cast<SharedHolder *>(dd ^ Shared)->release(); } QQmlMetaObjectPointer(const QQmlMetaObjectPointer &other) @@ -111,9 +112,10 @@ public: const QMetaObject *metaObject() const { - if (d & Shared) - return reinterpret_cast<SharedHolder *>(d ^ Shared)->metaObject; - return reinterpret_cast<const QMetaObject *>(d.loadRelaxed()); + const auto dd = d.loadAcquire(); + if (dd & Shared) + return reinterpret_cast<SharedHolder *>(dd ^ Shared)->metaObject; + return reinterpret_cast<const QMetaObject *>(dd); } bool isShared() const |