diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-10-01 10:10:29 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2014-10-01 18:25:47 +0200 |
commit | 5e01d3f64265867284e6bba8d1881e10c5d7605c (patch) | |
tree | 7a27df121075d6744b058736732b2cdd5c444f13 /src/corelib/tools/qlist.h | |
parent | b1482795ee58286c1082b1b1cfac1a160d3837e8 (diff) |
QList: iterate forward in count()/contains()
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: Ib62cf0a6f2a33d186cb174b23b0d6bb2891b6c63
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r-- | src/corelib/tools/qlist.h | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index b56afe15c2..9704c7b953 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -921,9 +921,9 @@ Q_OUTOFLINE_TEMPLATE int QList<T>::lastIndexOf(const T &t, int from) const template <typename T> Q_OUTOFLINE_TEMPLATE bool QList<T>::contains(const T &t) const { - Node *b = reinterpret_cast<Node *>(p.begin()); - Node *i = reinterpret_cast<Node *>(p.end()); - while (i-- != b) + Node *e = reinterpret_cast<Node *>(p.end()); + Node *i = reinterpret_cast<Node *>(p.begin()); + for (; i != e; ++i) if (i->t() == t) return true; return false; @@ -933,9 +933,9 @@ template <typename T> Q_OUTOFLINE_TEMPLATE int QList<T>::count(const T &t) const { int c = 0; - Node *b = reinterpret_cast<Node *>(p.begin()); - Node *i = reinterpret_cast<Node *>(p.end()); - while (i-- != b) + Node *e = reinterpret_cast<Node *>(p.end()); + Node *i = reinterpret_cast<Node *>(p.begin()); + for (; i != e; ++i) if (i->t() == t) ++c; return c; |