QList: iterate forward in 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: Id2388eab2339c24deb93095495d87056a9c57133
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2014-10-01 10:11:11 +02:00
parent db1db22818
commit f17e0b5893

View File

@ -791,10 +791,10 @@ int QVector<T>::lastIndexOf(const T &t, int from) const
template <typename T>
bool QVector<T>::contains(const T &t) const
{
T* b = d->begin();
T* i = d->end();
while (i != b)
if (*--i == t)
T* i = d->begin();
T* e = d->end();
for (; i != e; ++i)
if (*i == t)
return true;
return false;
}