summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qbitarray.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2013-08-28 18:37:00 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-31 23:03:03 +0200
commit260a983052d0e42ccedaf49832e8dfecaa5ed1d7 (patch)
tree00867375b3a088fd81497bb3a91c9131fe90815b /src/corelib/tools/qbitarray.cpp
parente13e90fb55149833aa96e46087f47e4dd9ca0a75 (diff)
Improve QBitArray's construction performance a little
Ask for an uninitialized byte array, since we're about to memset(3) it anyway. And don't overwrite the initial byte either. Change-Id: I2caa2ef395ad5684416e6cd336c0444de7787b5d Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools/qbitarray.cpp')
-rw-r--r--src/corelib/tools/qbitarray.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/corelib/tools/qbitarray.cpp b/src/corelib/tools/qbitarray.cpp
index cae8267772..fb60534495 100644
--- a/src/corelib/tools/qbitarray.cpp
+++ b/src/corelib/tools/qbitarray.cpp
@@ -136,15 +136,14 @@ QT_BEGIN_NAMESPACE
initialized with \a value, which defaults to false (0).
*/
QBitArray::QBitArray(int size, bool value)
+ : d(size <= 0 ? 0 : 1 + (size + 7)/8, Qt::Uninitialized)
{
Q_ASSERT_X(size >= 0, "QBitArray::QBitArray", "Size must be greater than or equal to 0.");
- if (size <= 0) {
- d.resize(0);
+ if (size <= 0)
return;
- }
- d.resize(1 + (size+7)/8);
+
uchar* c = reinterpret_cast<uchar*>(d.data());
- memset(c, value ? 0xff : 0, d.size());
+ memset(c + 1, value ? 0xff : 0, d.size() - 1);
*c = d.size()*8 - size;
if (value && size && size % 8)
*(c+1+size/8) &= (1 << (size%8)) - 1;