QByteArray: avoid detach() in a no-op replace()
When the the replacement has the same size as the replacee, but that size is zero, the whole operation is a no-op, and there's no need to detach(). [ChangeLog][QtCore][QByteArray] A replace(pos, n, after) call no longer detach()es when n == after.size() == 0. Pick-to: 6.3 6.2 Change-Id: I1e8d7c7fb6383f8bfea3212e49fca8a128535564 Reviewed-by: Lars Knoll <lars.knoll@qt.io>bb10
parent
ce14b6c2d3
commit
c953e5c417
|
|
@ -2170,9 +2170,10 @@ QByteArray &QByteArray::replace(qsizetype pos, qsizetype len, QByteArrayView aft
|
|||
}
|
||||
if (len == after.size() && (pos + len <= size())) {
|
||||
// same size: in-place replacement possible
|
||||
detach();
|
||||
if (len > 0)
|
||||
if (len > 0) {
|
||||
detach();
|
||||
memcpy(d.data() + pos, after.data(), len*sizeof(char));
|
||||
}
|
||||
return *this;
|
||||
} else {
|
||||
// ### optimize me
|
||||
|
|
|
|||
Loading…
Reference in New Issue