diff options
| author | Thiago Macieira <thiago.macieira@intel.com> | 2023-11-08 10:44:39 -0800 |
|---|---|---|
| committer | Thiago Macieira <thiago.macieira@intel.com> | 2023-12-07 14:55:07 -0800 |
| commit | db991cb4e12bca2e4ae72e03c8f078b27517f4e9 (patch) | |
| tree | 140e8de01bca57f00258698ffa3931b60b5033a3 /src/corelib/tools/qbitarray.cpp | |
| parent | 9b176281df15c6479510e5c13e12dba24ba31697 (diff) | |
QBitArray: replace the member operator~ with a hidden friend
Which takes the array to be inverted by value, so we get free move
semantics and allowing us to perform the negation in-place.
[ChangeLog][Potentially Source-Incompatible Changes] The bitwise AND,
OR, XOR, and NOT operator functions on QBitArray are now hidden
friends. This may cause source-incompatibility in unusual coding styles
(like 'array.operator~()') or with classes that have a casting 'operator
QBitArray()'.
Change-Id: I85b3fc2dd45c4693be13fffd1795ba1fbaf23769
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/tools/qbitarray.cpp')
| -rw-r--r-- | src/corelib/tools/qbitarray.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/corelib/tools/qbitarray.cpp b/src/corelib/tools/qbitarray.cpp index 4a3e929909f..54d587517ec 100644 --- a/src/corelib/tools/qbitarray.cpp +++ b/src/corelib/tools/qbitarray.cpp @@ -583,8 +583,9 @@ QBitArray &QBitArray::operator^=(const QBitArray &other) } /*! - Returns a bit array that contains the inverted bits of this bit - array. + \fn QBitArray QBitArray::operator~(QBitArray a) + Returns a bit array that contains the inverted bits of the bit + array \a a. Example: \snippet code/src_corelib_tools_qbitarray.cpp 11 @@ -592,12 +593,19 @@ QBitArray &QBitArray::operator^=(const QBitArray &other) \sa operator&(), operator|(), operator^() */ -QBitArray QBitArray::operator~() const +Q_NEVER_INLINE QBitArray QBitArray::inverted_inplace() && { qsizetype n = d.size(); - QBitArray result(QByteArrayData(n, n)); - const uchar *src = reinterpret_cast<const uchar *>(data_ptr().data()); - uchar *dst = reinterpret_cast<uchar *>(result.data_ptr().data()); + uchar *dst = reinterpret_cast<uchar *>(data_ptr().data()); + const uchar *src = dst; + QBitArray result([&] { + if (d.isDetached() || n == 0) + return std::move(d.data_ptr()); // invert in-place + + QByteArrayData tmp(n, n); + dst = reinterpret_cast<uchar *>(tmp.data()); + return tmp; + }()); uchar bitdiff = 8; if (n) |
