From f90308c0c3c1d888853faf8edc5c40be081dcb6d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 26 Aug 2014 10:18:47 +0200 Subject: QVector: check d for equality before d->size for inequality Assuming the CPU has already loaded 'this', the value of 'd' is just an indirect load away. The value of d->size, however, is two indirect loads away, one of which is the load of 'd'. So it makes more sense to check for d-pointer equality first, as that can proceed in parallel with the fetch for d->size, which the CPU may speculatively trigger. In addition, at least GCC in release mode after this change doesn't set up the stack frame if the d-pointer check succeeds. Change-Id: I61f9b245070dd1742fca6ccb8d4936a0b1aa7c07 Reviewed-by: Giuseppe D'Angelo --- src/corelib/tools/qvector.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index c92f43e1fc..f26d61eb9c 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -711,10 +711,10 @@ typename QVector::iterator QVector::erase(iterator abegin, iterator aend) template bool QVector::operator==(const QVector &v) const { - if (d->size != v.d->size) - return false; if (d == v.d) return true; + if (d->size != v.d->size) + return false; T* b = d->begin(); T* i = b + d->size; T* j = v.d->end(); -- cgit v1.2.3