QByteArray::replace(): use std::string instead of QVLA<char>

QVLA preallocates space for 256 entries, and while that should be
enough for most uses, it may be too much in the way of stack usage.

Instead of using a QVLA with a non-standard preallocation, use the
more compact std::string benefitting from its SSO.

Pick-to: 6.8 6.5
Change-Id: Ia22543fb287a1976f316f7a4d27b23a22f511463
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
(cherry picked from commit 7c21630ce625817f1dc8e7182023b3fc6d36ac37)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-02-19 16:58:53 +01:00 committed by Qt Cherry-pick Bot
parent b0e9665e7d
commit d561d864eb

View File

@ -33,6 +33,7 @@
#include <algorithm>
#include <QtCore/q26numeric.h>
#include <string>
#ifdef Q_OS_WIN
# if !defined(QT_BOOTSTRAPPED) && (defined(QT_NO_CAST_FROM_ASCII) || defined(QT_NO_CAST_FROM_BYTEARRAY))
@ -2514,7 +2515,7 @@ QByteArray &QByteArray::replace(QByteArrayView before, QByteArrayView after)
return *this;
// protect against before or after being part of this
QVarLengthArray<char> pinnedNeedle, pinnedReplacement;
std::string pinnedNeedle, pinnedReplacement;
if (QtPrivate::q_points_into_range(a, d)) {
pinnedReplacement.assign(a, a + asize);
a = pinnedReplacement.data();