Do 64-bit loops in QBitArray::count(bool)

On 64-bit platforms, with unaligned loads, this is defintely an
improvement since we can run fewer instructions. On 32-bit platforms
with unaligned loads, we'll do the exact same number of loads. On
platforms without unaligned loads, it's no worse.

Change-Id: Idd5dd5213975d77bbc3adf486adbf6f8ef071341
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
bb10
Thiago Macieira 2013-09-12 15:31:50 -07:00 committed by The Qt Project
parent 6f0fdaa76c
commit 6b9d125621
1 changed files with 6 additions and 1 deletions

View File

@ -194,7 +194,12 @@ int QBitArray::count(bool on) const
// it's the QByteArray implicit NUL, so it will not change the bit count
const quint8 *const end = reinterpret_cast<const quint8 *>(d.end());
while (bits + 3 <= end) {
while (bits + 7 <= end) {
quint64 v = qUnalignedLoad<quint64>(bits);
bits += 8;
numBits += int(qPopulationCount(v));
}
if (bits + 3 <= end) {
quint32 v = qUnalignedLoad<quint32>(bits);
bits += 4;
numBits += int(qPopulationCount(v));