From ddd61b4aec7d17741faffe988b44c7c0a19ce71f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 26 Aug 2014 10:53:42 +0200 Subject: 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 --- src/corelib/tools/qlist.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/corelib/tools') 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::operator==(const QList &l) const return true; if (p.size() != l.p.size()) return false; + return this->op_eq_impl(l, MemoryLayout()); +} + +template +inline bool QList::op_eq_impl(const QList &l, QListData::NotArrayCompatibleLayout) const +{ Node *i = reinterpret_cast(p.begin()); Node *e = reinterpret_cast(p.end()); Node *li = reinterpret_cast(l.p.begin()); @@ -806,6 +814,15 @@ Q_OUTOFLINE_TEMPLATE bool QList::operator==(const QList &l) const return true; } +template +inline bool QList::op_eq_impl(const QList &l, QListData::ArrayCompatibleLayout) const +{ + const T *lb = reinterpret_cast(l.p.begin()); + const T *b = reinterpret_cast(p.begin()); + const T *e = reinterpret_cast(p.end()); + return std::equal(b, e, lb); +} + template Q_OUTOFLINE_TEMPLATE void QList::dealloc(QListData::Data *data) { -- cgit v1.2.3