summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qbytearray.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2021-12-16 10:09:29 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-01-03 11:22:53 +0000
commitc953e5c41750ec886880cfb2cedb89f2886e5424 (patch)
tree703d4e90ef1b08eb4efecdae8e8b902f2970ef3f /src/corelib/text/qbytearray.cpp
parentce14b6c2d3463f73d2e266af2dd97b942f2af109 (diff)
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>
Diffstat (limited to 'src/corelib/text/qbytearray.cpp')
-rw-r--r--src/corelib/text/qbytearray.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index a03462561f..e339f2fef5 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -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