diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-04-19 19:12:21 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-09-03 10:57:10 (GMT) |
commit | da0e1a682362144b9f13b4c564f86e09efb681bb (patch) | |
tree | 8cbf68a93b055515b2a56d9e0667c530b27e39e2 /src/corelib | |
parent | 605aa0cf1889110620dc0d5d84066be8177fe9c2 (diff) | |
download | Qt-da0e1a682362144b9f13b4c564f86e09efb681bb.zip Qt-da0e1a682362144b9f13b4c564f86e09efb681bb.tar.gz Qt-da0e1a682362144b9f13b4c564f86e09efb681bb.tar.bz2 |
C++0x move operators
This makes assignement faster from temporaries, as the operator is
fully inline, and doesn't do any atomic operations.
Reviewed-by: joao
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qdir.h | 4 | ||||
-rw-r--r-- | src/corelib/io/qfileinfo.h | 4 | ||||
-rw-r--r-- | src/corelib/io/qurl.h | 4 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qbitarray.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qbytearray.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qcontiguouscache.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qhash.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qlinkedlist.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qlist.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qmap.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qregexp.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qset.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qshareddata.h | 8 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 7 | ||||
-rw-r--r-- | src/corelib/tools/qstring.h | 5 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 6 |
17 files changed, 76 insertions, 2 deletions
diff --git a/src/corelib/io/qdir.h b/src/corelib/io/qdir.h index 28da271..0a56304 100644 --- a/src/corelib/io/qdir.h +++ b/src/corelib/io/qdir.h @@ -129,6 +129,10 @@ public: QDir &operator=(const QDir &); QDir &operator=(const QString &path); +#ifdef Q_COMPILER_RVALUE_REFS + inline QDir &operator=(QDir &&other) + { qSwap(d_ptr, other.d_ptr); return *this; } +#endif void setPath(const QString &path); QString path() const; diff --git a/src/corelib/io/qfileinfo.h b/src/corelib/io/qfileinfo.h index 7e82aed..f0c6d60 100644 --- a/src/corelib/io/qfileinfo.h +++ b/src/corelib/io/qfileinfo.h @@ -67,6 +67,10 @@ public: ~QFileInfo(); QFileInfo &operator=(const QFileInfo &fileinfo); +#ifdef Q_COMPILER_RVALUE_REFS + inline QFileInfo&operator=(QFileInfo &&other) + { qSwap(d_ptr, other.d_ptr); return *this; } +#endif bool operator==(const QFileInfo &fileinfo); // 5.0 - remove me bool operator==(const QFileInfo &fileinfo) const; inline bool operator!=(const QFileInfo &fileinfo) { return !(operator==(fileinfo)); } // 5.0 - remove me diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h index 162aa7c..563be5f 100644 --- a/src/corelib/io/qurl.h +++ b/src/corelib/io/qurl.h @@ -94,6 +94,10 @@ public: #ifndef QT_NO_URL_CAST_FROM_STRING QUrl &operator =(const QString &url); #endif +#ifdef Q_COMPILER_RVALUE_REFS + inline QUrl &operator=(QUrl &&other) + { qSwap(d, other.d); return *this; } +#endif ~QUrl(); void setUrl(const QString &url); diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index a4d45f6..b267954 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -219,6 +219,10 @@ class Q_CORE_EXPORT QVariant QVariant(Qt::GlobalColor color); QVariant& operator=(const QVariant &other); +#ifdef Q_COMPILER_RVALUE_REFS + inline QVariant &operator=(QVariant &&other) + { qSwap(d, other.d); return *this; } +#endif Type type() const; int userType() const; diff --git a/src/corelib/tools/qbitarray.h b/src/corelib/tools/qbitarray.h index 60cdc9c..bd79904 100644 --- a/src/corelib/tools/qbitarray.h +++ b/src/corelib/tools/qbitarray.h @@ -63,6 +63,10 @@ public: explicit QBitArray(int size, bool val = false); QBitArray(const QBitArray &other) : d(other.d) {} inline QBitArray &operator=(const QBitArray &other) { d = other.d; return *this; } +#ifdef Q_COMPILER_RVALUE_REFS + inline QBitArray &operator=(QBitArray &&other) + { qSwap(d, other.d); return *this; } +#endif inline int size() const { return (d.size() << 3) - *d.constData(); } inline int count() const { return (d.size() << 3) - *d.constData(); } diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index a3fe3f5..3cdcaab 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -144,6 +144,10 @@ public: QByteArray &operator=(const QByteArray &); QByteArray &operator=(const char *str); +#ifdef Q_COMPILER_RVALUE_REFS + inline QByteArray &operator=(QByteArray &&other) + { qSwap(d, other.d); return *this; } +#endif inline int size() const; bool isEmpty() const; diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h index f767962..4c1a846 100644 --- a/src/corelib/tools/qcontiguouscache.h +++ b/src/corelib/tools/qcontiguouscache.h @@ -110,6 +110,10 @@ public: inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; } QContiguousCache<T> &operator=(const QContiguousCache<T> &other); +#ifdef Q_COMPILER_RVALUE_REFS + inline QContiguousCache<T> &operator=(QContiguousCache<T> &&other) + { qSwap(d, other.d); return *this; } +#endif bool operator==(const QContiguousCache<T> &other) const; inline bool operator!=(const QContiguousCache<T> &other) const { return !(*this == other); } diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 14ed514..992ff33 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -283,6 +283,10 @@ public: inline ~QHash() { if (!d->ref.deref()) freeData(d); } QHash<Key, T> &operator=(const QHash<Key, T> &other); +#ifdef Q_COMPILER_RVALUE_REFS + inline QHash<Key, T> &operator=(QHash<Key, T> &&other) + { qSwap(d, other.d); return *this; } +#endif bool operator==(const QHash<Key, T> &other) const; inline bool operator!=(const QHash<Key, T> &other) const { return !(*this == other); } diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h index 9b3efa3..c087944 100644 --- a/src/corelib/tools/qlinkedlist.h +++ b/src/corelib/tools/qlinkedlist.h @@ -85,6 +85,10 @@ public: inline QLinkedList(const QLinkedList<T> &l) : d(l.d) { d->ref.ref(); if (!d->sharable) detach(); } ~QLinkedList(); QLinkedList<T> &operator=(const QLinkedList<T> &); +#ifdef Q_COMPILER_RVALUE_REFS + inline QLinkedList<T> &operator=(QLinkedList<T> &&other) + { qSwap(d, other.d); return *this; } +#endif bool operator==(const QLinkedList<T> &l) const; inline bool operator!=(const QLinkedList<T> &l) const { return !(*this == l); } diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 1282bca..b1d07bd 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -118,6 +118,10 @@ public: inline QList(const QList<T> &l) : d(l.d) { d->ref.ref(); if (!d->sharable) detach_helper(); } ~QList(); QList<T> &operator=(const QList<T> &l); +#ifdef Q_COMPILER_RVALUE_REFS + inline QList &operator=(QList &&other) + { qSwap(d, other.d); return *this; } +#endif bool operator==(const QList<T> &l) const; inline bool operator!=(const QList<T> &l) const { return !(*this == l); } diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 08f5a35..ce8fd75 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -185,6 +185,10 @@ public: inline ~QMap() { if (!d) return; if (!d->ref.deref()) freeData(d); } QMap<Key, T> &operator=(const QMap<Key, T> &other); +#ifdef Q_COMPILER_RVALUE_REFS + inline QMap<Key, T> &operator=(QMap<Key, T> &&other) + { qSwap(d, other.d); return *this; } +#endif #ifndef QT_NO_STL explicit QMap(const typename std::map<Key, T> &other); std::map<Key, T> toStdMap() const; diff --git a/src/corelib/tools/qregexp.h b/src/corelib/tools/qregexp.h index e19c130..0b4a702 100644 --- a/src/corelib/tools/qregexp.h +++ b/src/corelib/tools/qregexp.h @@ -76,6 +76,10 @@ public: QRegExp(const QRegExp &rx); ~QRegExp(); QRegExp &operator=(const QRegExp &rx); +#ifdef Q_COMPILER_RVALUE_REFS + inline QRegExp &operator=(QRegExp &&other) + { qSwap(priv,other.priv); return *this; } +#endif bool operator==(const QRegExp &rx) const; inline bool operator!=(const QRegExp &rx) const { return !operator==(rx); } diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index fe50d4d..dc3c45a 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -61,6 +61,10 @@ public: inline QSet<T> &operator=(const QSet<T> &other) { q_hash = other.q_hash; return *this; } +#ifdef Q_COMPILER_RVALUE_REFS + inline QSet<T> &operator=(QSet<T> &&other) + { qSwap(q_hash, other.q_hash); return *this; } +#endif inline bool operator==(const QSet<T> &other) const { return q_hash == other.q_hash; } diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h index 1ae2fa9..b646a9d 100644 --- a/src/corelib/tools/qshareddata.h +++ b/src/corelib/tools/qshareddata.h @@ -113,6 +113,10 @@ public: } return *this; } +#ifdef Q_COMPILER_RVALUE_REFS + inline QSharedDataPointer<T> &operator=(QSharedDataPointer<T> &&other) + { qSwap(d, other.d); return *this; } +#endif inline bool operator!() const { return !d; } @@ -192,6 +196,10 @@ public: } return *this; } +#ifdef Q_COMPILER_RVALUE_REFS + inline QSharedDataPointer<T> &operator=(QSharedDataPointer<T> &&other) + { qSwap(d, other.d); return *this; } +#endif inline bool operator!() const { return !d; } diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index bb06f3a..20dda12 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -465,6 +465,13 @@ public: BaseClass::internalCopy(other); return *this; } +#ifdef Q_COMPILER_RVALUE_REFS + inline QSharedPointer<T> &operator=(QSharedPointer<T> &&other) + { + QSharedPointer<T>::internalSwap(other); + return *this; + } +#endif template <class X> inline QSharedPointer(const QSharedPointer<X> &other) : BaseClass(other) diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 2633e78..589fdc2 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -104,7 +104,10 @@ public: QString &operator=(QChar c); QString &operator=(const QString &); inline QString &operator=(const QLatin1String &); - +#ifdef Q_COMPILER_RVALUE_REFS + inline QString &operator=(QString &&other) + { qSwap(d, other.d); return *this; } +#endif inline int size() const { return d->size; } inline int count() const { return d->size; } inline int length() const; diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 2f0ad42..c001699 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -118,6 +118,11 @@ public: inline QVector(const QVector<T> &v) : d(v.d) { d->ref.ref(); if (!d->sharable) detach_helper(); } inline ~QVector() { if (!d) return; if (!d->ref.deref()) free(p); } QVector<T> &operator=(const QVector<T> &v); +#ifdef Q_COMPILER_RVALUE_REFS + inline QVector<T> operator=(QVector<T> &&other) + { qSwap(p, other.p); return *this; } +#endif + bool operator==(const QVector<T> &v) const; inline bool operator!=(const QVector<T> &v) const { return !(*this == v); } @@ -297,7 +302,6 @@ public: inline std::vector<T> toStdVector() const { std::vector<T> tmp; qCopy(constBegin(), constEnd(), std::back_inserter(tmp)); return tmp; } #endif - private: friend class QRegion; // Optimization for QRegion::rects() |