diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2025-07-11 11:29:34 +0200 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2025-07-15 00:25:35 +0200 |
| commit | 8e398cec88f6019edc83e52cab64e3ef52bef173 (patch) | |
| tree | 7e100436cb687d79735f211c51bf0e4aadecc6f2 /src/corelib/io/qdebug.cpp | |
| parent | 8efc9d6d2196eebc803c03bbff163d37c5668ea9 (diff) | |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qdebug.cpp')
| -rw-r--r-- | src/corelib/io/qdebug.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
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); |
