diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-04-24 15:11:45 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-04-26 09:56:56 +0000 |
commit | 0f4212cbdf1756833ddd22db4b3c6d92bc80f203 (patch) | |
tree | e494490a7852d58b5cd8b355271934b7954269ca /src/qml/qml/ftw | |
parent | 99b7f1b50267071023bcc35e094b61eb0e568b5d (diff) |
Minor cleanup in QQmlRefPointer
Add rvalue constructor and assignment operator, to reduce the amount of
atomic operations as a consequence of the typeloader changes that
replace the manual reference counting with QQmlRefPointer usage.
Change-Id: Id36be54e717cf2e83b0027b818f11e20b4fde0ce
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/qml/ftw')
-rw-r--r-- | src/qml/qml/ftw/qqmlrefcount_p.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/qml/qml/ftw/qqmlrefcount_p.h b/src/qml/qml/ftw/qqmlrefcount_p.h index e8fa1ff2a6..d32a08e0f5 100644 --- a/src/qml/qml/ftw/qqmlrefcount_p.h +++ b/src/qml/qml/ftw/qqmlrefcount_p.h @@ -85,9 +85,11 @@ public: inline QQmlRefPointer(); inline QQmlRefPointer(T *, Mode m = AddRef); inline QQmlRefPointer(const QQmlRefPointer<T> &); + inline QQmlRefPointer(QQmlRefPointer<T> &&); inline ~QQmlRefPointer(); inline QQmlRefPointer<T> &operator=(const QQmlRefPointer<T> &o); + inline QQmlRefPointer<T> &operator=(QQmlRefPointer<T> &&o); inline bool isNull() const { return !o; } @@ -158,6 +160,12 @@ QQmlRefPointer<T>::QQmlRefPointer(const QQmlRefPointer<T> &other) if (o) o->addref(); } +template <class T> +QQmlRefPointer<T>::QQmlRefPointer(QQmlRefPointer<T> &&other) + : o(other.take()) +{ +} + template<class T> QQmlRefPointer<T>::~QQmlRefPointer() { @@ -173,6 +181,14 @@ QQmlRefPointer<T> &QQmlRefPointer<T>::operator=(const QQmlRefPointer<T> &other) return *this; } +template <class T> +QQmlRefPointer<T> &QQmlRefPointer<T>::operator=(QQmlRefPointer<T> &&other) +{ + QQmlRefPointer<T> m(std::move(other)); + qSwap(o, m.o); + return *this; +} + /*! Takes ownership of \a other. take() does *not* add a reference, as it assumes ownership of the callers reference of other. |