diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2023-11-08 09:53:03 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2023-12-12 22:59:23 -0800 |
commit | 54c373faa4f9582fd09a802727821fd544a7b2c5 (patch) | |
tree | e3474743026adee43c3745d1f7e439e51a4788a8 /tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp | |
parent | ce5aaf1e434b6e2e482347b40524edeccecb1665 (diff) |
QBitArray: improve memory allocation in the binary bitwise operators
Instead of creating a temporary copy of one of the two sides (which will
share QByteArray), create one with the correct target size such that it
is already detached.
Drive-by move them to hidden friends.
Pick-to: 6.7
Change-Id: I85b3fc2dd45c4693be13fffd1795b74eeaf3be71
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp')
-rw-r--r-- | tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp b/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp index 1431221fd5..5de1e9bb43 100644 --- a/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp +++ b/tests/auto/corelib/tools/qbitarray/tst_qbitarray.cpp @@ -43,12 +43,21 @@ private slots: // operator &= void operator_andeq_data(); void operator_andeq(); + // operator & + void operator_and_data() { operator_andeq_data(); } + void operator_and(); // operator |= void operator_oreq_data(); void operator_oreq(); + // operator | + void operator_or_data() { operator_oreq_data(); } + void operator_or(); // operator ^= void operator_xoreq_data(); void operator_xoreq(); + // operator ^ + void operator_xor_data() { operator_xoreq_data(); } + void operator_xor(); // operator ~ void operator_neg_data(); void operator_neg(); @@ -306,6 +315,24 @@ void tst_QBitArray::operator_andeq() QCOMPARE(input1, res); } +void tst_QBitArray::operator_and() +{ + QFETCH(QBitArray, input1); + QFETCH(QBitArray, input2); + QFETCH(QBitArray, res); + + QBitArray result = input1 & input2; + QCOMPARE(result, res); + + // operation is commutative + result = input2 & input1; + QCOMPARE(result, res); + + // operation is idempotent + result = result & result; + QCOMPARE(result, res); +} + void tst_QBitArray::operator_oreq_data() { QTest::addColumn<QBitArray>("input1"); @@ -357,6 +384,24 @@ void tst_QBitArray::operator_oreq() QCOMPARE(input1, res); } +void tst_QBitArray::operator_or() +{ + QFETCH(QBitArray, input1); + QFETCH(QBitArray, input2); + QFETCH(QBitArray, res); + + QBitArray result = input1 | input2; + QCOMPARE(result, res); + + // operation is commutative + result = input2 | input1; + QCOMPARE(result, res); + + // operation is idempotent + result = result | result; + QCOMPARE(result, res); +} + void tst_QBitArray::operator_xoreq_data() { QTest::addColumn<QBitArray>("input1"); @@ -406,6 +451,27 @@ void tst_QBitArray::operator_xoreq() QCOMPARE(input1, res); } +void tst_QBitArray::operator_xor() +{ + QFETCH(QBitArray, input1); + QFETCH(QBitArray, input2); + QFETCH(QBitArray, res); + + QBitArray result = input1 ^ input2; + QCOMPARE(result, res); + + // operation is commutative + result = input2 ^ input1; + QCOMPARE(result, res); + + // XORing with oneself is nilpotent + result = input1 ^ input1; + QCOMPARE(result, QBitArray(input1.size())); + result = input2 ^ input2; + QCOMPARE(result, QBitArray(input2.size())); + result = res ^ res; + QCOMPARE(result, QBitArray(res.size())); +} void tst_QBitArray::operator_neg_data() { |