diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-10-01 10:10:00 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2014-10-01 18:25:41 +0200 |
commit | b1482795ee58286c1082b1b1cfac1a160d3837e8 (patch) | |
tree | 519598e06569f2ef62b1301dc262d670f4e20493 /src/corelib/tools/qlist.h | |
parent | 9618fb7262b1b23ef5420ee83aa3b6b697eedc3e (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r-- | src/corelib/tools/qlist.h | 9 |
1 files 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<T>::operator==(const QList<T> &l) const return true; if (p.size() != l.p.size()) return false; - Node *i = reinterpret_cast<Node *>(p.end()); - Node *b = reinterpret_cast<Node *>(p.begin()); - Node *li = reinterpret_cast<Node *>(l.p.end()); - while (i != b) { - --i; --li; + Node *i = reinterpret_cast<Node *>(p.begin()); + Node *e = reinterpret_cast<Node *>(p.end()); + Node *li = reinterpret_cast<Node *>(l.p.begin()); + for (; i != e; ++i, ++li) { if (!(i->t() == li->t())) return false; } |