diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-08-26 10:18:47 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2014-08-28 09:52:36 +0200 |
commit | f90308c0c3c1d888853faf8edc5c40be081dcb6d (patch) | |
tree | cc1dab4c39c504c85ea785e43c81240863934e8e /src/corelib/tools | |
parent | da72e1b0e8fce7c221d5aaafe336f01e68d9f97a (diff) |
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 <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qvector.h | 4 |
1 files changed, 2 insertions, 2 deletions
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<T>::iterator QVector<T>::erase(iterator abegin, iterator aend) template <typename T> bool QVector<T>::operator==(const QVector<T> &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(); |