summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlist.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-08-26 10:53:42 +0200
committerMarc Mutz <marc.mutz@kdab.com>2015-02-17 15:05:23 +0000
commitddd61b4aec7d17741faffe988b44c7c0a19ce71f (patch)
treeb876bb7178959ce7e2ed5af69a205e6369a2f09b /src/corelib/tools/qlist.h
parent18885297de880493831f63d20a8d45c6689a01b8 (diff)
QList: share implementation of operator== with QVector where possible
Same change as was already applied for count() and contains(). Change-Id: Ibd62e4b36e03741993ba33e730c9449ef19bff5f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r--src/corelib/tools/qlist.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 5d6cf9fe15..57e67d52d7 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -379,6 +379,8 @@ private:
}
private:
+ inline bool op_eq_impl(const QList &other, QListData::NotArrayCompatibleLayout) const;
+ inline bool op_eq_impl(const QList &other, QListData::ArrayCompatibleLayout) const;
inline bool contains_impl(const T &, QListData::NotArrayCompatibleLayout) const;
inline bool contains_impl(const T &, QListData::ArrayCompatibleLayout) const;
inline int count_impl(const T &, QListData::NotArrayCompatibleLayout) const;
@@ -796,6 +798,12 @@ Q_OUTOFLINE_TEMPLATE bool QList<T>::operator==(const QList<T> &l) const
return true;
if (p.size() != l.p.size())
return false;
+ return this->op_eq_impl(l, MemoryLayout());
+}
+
+template <typename T>
+inline bool QList<T>::op_eq_impl(const QList &l, QListData::NotArrayCompatibleLayout) const
+{
Node *i = reinterpret_cast<Node *>(p.begin());
Node *e = reinterpret_cast<Node *>(p.end());
Node *li = reinterpret_cast<Node *>(l.p.begin());
@@ -807,6 +815,15 @@ Q_OUTOFLINE_TEMPLATE bool QList<T>::operator==(const QList<T> &l) const
}
template <typename T>
+inline bool QList<T>::op_eq_impl(const QList &l, QListData::ArrayCompatibleLayout) const
+{
+ const T *lb = reinterpret_cast<const T*>(l.p.begin());
+ const T *b = reinterpret_cast<const T*>(p.begin());
+ const T *e = reinterpret_cast<const T*>(p.end());
+ return std::equal(b, e, lb);
+}
+
+template <typename T>
Q_OUTOFLINE_TEMPLATE void QList<T>::dealloc(QListData::Data *data)
{
node_destruct(reinterpret_cast<Node *>(data->array + data->begin),