Skip to content

Commit

Permalink
QBitArray: simplify (size, value) ctor
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
marcmutz committed Feb 2, 2024
1 parent 9219e8f commit 0d6ca27
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/corelib/tools/qbitarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 0d6ca27

Please sign in to comment.