From f17e0b589309eda4dfbbca266fbe3d87e548d8a3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 1 Oct 2014 10:11:11 +0200 Subject: 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 --- src/corelib/tools/qvector.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/corelib/tools/qvector.h') diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 83b836711d..8b0804e5df 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -791,10 +791,10 @@ int QVector::lastIndexOf(const T &t, int from) const template bool QVector::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; } -- cgit v1.2.3