QBitArray: simplify (size, value) ctor

Don't do the memset() manually just to save re-writing the single
leading byte. Pass the initial values to the QByteArray constructor
directly.

Pick-to: 6.7
Change-Id: I67daf446bebb8c8c6b05d235746ee43604f42445
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2024-01-30 11:19:41 +01:00
parent 9219e8ff1d
commit 0d6ca27517

View File

@ -135,14 +135,12 @@ static void adjust_head_and_tail(char *data, qsizetype storageSize, qsizetype lo
initialized with \a value, which defaults to false (0).
*/
QBitArray::QBitArray(qsizetype size, bool value)
: d(allocation_size(size), Qt::Uninitialized)
: d(allocation_size(size), value ? 0xFF : 0x00)
{
Q_ASSERT_X(size >= 0, "QBitArray::QBitArray", "Size must be greater than or equal to 0.");
if (size <= 0)
return;
uchar *c = reinterpret_cast<uchar *>(d.data());
memset(c + 1, value ? 0xff : 0, d.size() - 1);
adjust_head_and_tail(d.data(), d.size(), size);
}