QByteArray: don't recurse when needle or replacement alias *this
While the idea to delay the construction of the QVLAs until we know we need them is elegant, we're doing a lot of checks twice or thrice this way, so merely re-set the a, b pointers and otherwise continue executing. This requires us to default-construct the QVLAs before potentially assign()ing to them, but that ought to be cheap, given the compiler can see everything that's going on in QVLA. Pick-to: 6.9 6.8 6.5 Change-Id: I4e42d5ab48711af91cc1785171524be5fb45ae2f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
This commit is contained in:
parent
b93575de01
commit
4308ab70ca
@ -2537,13 +2537,14 @@ QByteArray &QByteArray::replace(QByteArrayView before, QByteArrayView after)
|
||||
return *this;
|
||||
|
||||
// protect against before or after being part of this
|
||||
QVarLengthArray<char> pinnedNeedle, pinnedReplacement;
|
||||
if (QtPrivate::q_points_into_range(a, d)) {
|
||||
QVarLengthArray copy(a, a + asize);
|
||||
return replace(before, QByteArrayView{copy});
|
||||
pinnedReplacement.assign(a, a + asize);
|
||||
a = pinnedReplacement.data();
|
||||
}
|
||||
if (QtPrivate::q_points_into_range(b, d)) {
|
||||
QVarLengthArray copy(b, b + bsize);
|
||||
return replace(QByteArrayView{copy}, after);
|
||||
pinnedNeedle.assign(b, b + bsize);
|
||||
b = pinnedNeedle.data();
|
||||
}
|
||||
|
||||
QByteArrayMatcher matcher(b, bsize);
|
||||
|
Loading…
x
Reference in New Issue
Block a user