summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-04-19 19:12:21 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-09-03 10:57:10 (GMT)
commitda0e1a682362144b9f13b4c564f86e09efb681bb (patch)
tree8cbf68a93b055515b2a56d9e0667c530b27e39e2 /src/corelib/tools
parent605aa0cf1889110620dc0d5d84066be8177fe9c2 (diff)
downloadQt-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/tools')
-rw-r--r--src/corelib/tools/qbitarray.h4
-rw-r--r--src/corelib/tools/qbytearray.h4
-rw-r--r--src/corelib/tools/qcontiguouscache.h4
-rw-r--r--src/corelib/tools/qhash.h4
-rw-r--r--src/corelib/tools/qlinkedlist.h4
-rw-r--r--src/corelib/tools/qlist.h4
-rw-r--r--src/corelib/tools/qmap.h4
-rw-r--r--src/corelib/tools/qregexp.h4
-rw-r--r--src/corelib/tools/qset.h4
-rw-r--r--src/corelib/tools/qshareddata.h8
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h7
-rw-r--r--src/corelib/tools/qstring.h5
-rw-r--r--src/corelib/tools/qvector.h6
13 files changed, 60 insertions, 2 deletions
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()