From b1482795ee58286c1082b1b1cfac1a160d3837e8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 1 Oct 2014 10:10:00 +0200 Subject: [PATCH] QList: iterate forward in operator== After much head-scratching, we found no reason for the backwards iteration. Indeed, forward iteration should be slightly faster than backwards, because it operates in the direction in which cache-lines are filled, usually. This is in preparation of using std algorithms instead of hand-written loops. It avoids having to use std::reverse_iterator. Change-Id: I31be6ad2b6d78ccce7e8a8f8f8b9e0af62f7471b Reviewed-by: Thiago Macieira --- src/corelib/tools/qlist.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 326a276f40..b56afe15c2 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -770,11 +770,10 @@ Q_OUTOFLINE_TEMPLATE bool QList::operator==(const QList &l) const return true; if (p.size() != l.p.size()) return false; - Node *i = reinterpret_cast(p.end()); - Node *b = reinterpret_cast(p.begin()); - Node *li = reinterpret_cast(l.p.end()); - while (i != b) { - --i; --li; + Node *i = reinterpret_cast(p.begin()); + Node *e = reinterpret_cast(p.end()); + Node *li = reinterpret_cast(l.p.begin()); + for (; i != e; ++i, ++li) { if (!(i->t() == li->t())) return false; }