From 8e398cec88f6019edc83e52cab64e3ef52bef173 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 11 Jul 2025 11:29:34 +0200 Subject: De-pessimize QDebug::putByteArray() QTextStreamPrivate has had putString() overloads for QUtf8StringView (since e96a311334a5c70d5ffcc2ca5c10919952b99636) and QLatin1StringView (since 8515aa18716779985a5955292524fd683528c576) for ages, so use those instead of unconditionally converting to QString, as the original code from 62b752b3a2c9a69b5eb9a41b98293e83de347958 did. As a drive-by, turn the ternary operator into a switch to enable -Wswitch. Pick-to: 6.10 6.9 6.8 Change-Id: I5f250826704c0fdd4c32a4b88e3d0b4dda878318 Reviewed-by: Thiago Macieira --- src/corelib/io/qdebug.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/corelib/io/qdebug.cpp') diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 645f27798c4..70a688e40ff 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -332,9 +332,14 @@ void QDebug::putByteArray(const char *begin, size_t length, Latin1Content conten if (stream->noQuotes) { // no quotes, write the string directly too (no pretty-printing) // this respects the QTextStream state, though - QString string = content == ContainsLatin1 ? QString::fromLatin1(begin, qsizetype(length)) - : QString::fromUtf8(begin, qsizetype(length)); - stream->ts.d_ptr->putString(string); + switch (content) { + case Latin1Content::ContainsLatin1: + stream->ts.d_ptr->putString(QLatin1StringView{begin, qsizetype(length)}); + break; + case Latin1Content::ContainsBinary: + stream->ts.d_ptr->putString(QUtf8StringView{begin, qsizetype(length)}); + break; + } } else { // we'll reset the QTextStream formatting mechanisms, so save the state QDebugStateSaver saver(*this); -- cgit v1.2.3