diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2018-05-31 20:13:05 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2018-07-05 14:56:15 +0000 |
commit | 514972544a34aca0fd679b3a78521a0a1558d4e0 (patch) | |
tree | 8dbec4023d90d4022256071fadad39d67723c3c4 /src/corelib/serialization/qcborvalue.h | |
parent | fddf09363e1bbc6f6549eaf28def7699b2d87341 (diff) |
QCborArray & Map: implement move semantics
There isn't a lot of efficiency gain, since QCborValue was already
refcounted. This saves two atomic operations and an out-of-line call. In
the case of QCborValueRef (which includes QCborMap), because we reset
the container pointer in inline code, the call to QCborValue::dispose()
is also suppressed.
Change-Id: Icc2c231dc2c44abdb087fffd1533eaba7a9c70fa
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib/serialization/qcborvalue.h')
-rw-r--r-- | src/corelib/serialization/qcborvalue.h | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/corelib/serialization/qcborvalue.h b/src/corelib/serialization/qcborvalue.h index 717b123e68..b0282b0cd6 100644 --- a/src/corelib/serialization/qcborvalue.h +++ b/src/corelib/serialization/qcborvalue.h @@ -323,8 +323,14 @@ class Q_CORE_EXPORT QCborValueRef public: operator QCborValue() const { return concrete(); } - QCborValueRef &operator=(const QCborValue &other); - QCborValueRef &operator=(const QCborValueRef &other); + QCborValueRef(const QCborValueRef &) Q_DECL_NOTHROW = default; + QCborValueRef(QCborValueRef &&) Q_DECL_NOTHROW = default; + QCborValueRef &operator=(const QCborValue &other) + { assign(*this, other); return *this; } + QCborValueRef &operator=(QCborValue &&other) + { assign(*this, std::move(other)); other.container = nullptr; return *this; } + QCborValueRef &operator=(const QCborValueRef &other) + { assign(*this, other); return *this; } QCborValue::Type type() const { return concreteType(); } bool isInteger() const { return type() == QCborValue::Integer; } @@ -426,6 +432,9 @@ private: friend class QCborValueRefPtr; // static so we can pass this by value + static void assign(QCborValueRef that, const QCborValue &other); + static void assign(QCborValueRef that, QCborValue &&other); + static void assign(QCborValueRef that, const QCborValueRef other); static QCborValue concrete(QCborValueRef that) Q_DECL_NOTHROW; QCborValue concrete() const Q_DECL_NOTHROW { return concrete(*this); } |