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>
bb10
Marc Mutz 2014-08-26 10:18:47 +02:00
parent da72e1b0e8
commit f90308c0c3
1 changed files with 2 additions and 2 deletions

View File

@ -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();