summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlist.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-10-01 10:10:29 +0200
committerMarc Mutz <marc.mutz@kdab.com>2014-10-01 18:25:47 +0200
commit5e01d3f64265867284e6bba8d1881e10c5d7605c (patch)
tree7a27df121075d6744b058736732b2cdd5c444f13 /src/corelib/tools/qlist.h
parentb1482795ee58286c1082b1b1cfac1a160d3837e8 (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.h12
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;