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>
This commit is contained in:
parent
e13e90fb55
commit
260a983052
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user