diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2013-09-12 15:31:50 -0700 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-14 20:33:29 +0200 |
commit | 6b9d1256214839dd18b2ba5c6fc6f007cf21869f (patch) | |
tree | d2444cdaf5d29acbc1f7095ad4712d1076716c43 /src | |
parent | 6f0fdaa76ca44e2e2a4f1ff4310a22493c93ea23 (diff) | |
download | qtbase-6b9d1256214839dd18b2ba5c6fc6f007cf21869f.tar.gz |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qbitarray.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/corelib/tools/qbitarray.cpp b/src/corelib/tools/qbitarray.cpp index 169f0ce2c8..da2f48c071 100644 --- a/src/corelib/tools/qbitarray.cpp +++ b/src/corelib/tools/qbitarray.cpp @@ -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)); |