From 5bd7668403761fae0eb434ae7f7b9ce99f894802 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 11 May 2020 15:37:25 +0200 Subject: [PATCH] Replace some QString::fromRawData() with QStringViews around the code Even though QString::fromRawData() may not be as expensive as it used to be, it's still and out-of-line call _and_ more characters to type, so replace with QStringView construction where applicable. Change-Id: I70662da1bd45284f67e117e92b25d242afb8aaf8 Reviewed-by: Lars Knoll --- src/corelib/io/qurl.cpp | 2 +- src/corelib/kernel/qcore_mac.mm | 2 +- src/gui/painting/qpaintengine_raster.cpp | 2 +- src/gui/text/qtextobject.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 7b09db55668..308d993440b 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -1210,7 +1210,7 @@ static const QChar *parseIpFuture(QString &host, const QChar *begin, const QChar (begin[2].unicode() >= '0' && begin[2].unicode() <= '9')) { // this is so unlikely that we'll just go down the slow path // decode the whole string, skipping the "[vH." and "]" which we already know to be there - host += QString::fromRawData(begin, 4); + host += QStringView(begin, 4); // uppercase the version, if necessary if (begin[2].unicode() >= 'a') diff --git a/src/corelib/kernel/qcore_mac.mm b/src/corelib/kernel/qcore_mac.mm index a8aa1dad1fc..9ab91e465fa 100644 --- a/src/corelib/kernel/qcore_mac.mm +++ b/src/corelib/kernel/qcore_mac.mm @@ -193,7 +193,7 @@ QDebug operator<<(QDebug dbg, CFStringRef stringRef) return dbg << "CFStringRef(0x0)"; if (const UniChar *chars = CFStringGetCharactersPtr(stringRef)) - dbg << QString::fromRawData(reinterpret_cast(chars), CFStringGetLength(stringRef)); + dbg << QStringView(reinterpret_cast(chars), CFStringGetLength(stringRef)); else dbg << QString::fromCFString(stringRef); diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 13a6f5c16ac..24e0289c534 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -3156,7 +3156,7 @@ void QRasterPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textIte #ifdef QT_DEBUG_DRAW Q_D(QRasterPaintEngine); fprintf(stderr," - QRasterPaintEngine::drawTextItem(), (%.2f,%.2f), string=%s ct=%d\n", - p.x(), p.y(), QString::fromRawData(ti.chars, ti.num_chars).toLatin1().data(), + p.x(), p.y(), QStringView(ti.chars, ti.num_chars).toLatin1().data(), d->glyphCacheFormat); #endif diff --git a/src/gui/text/qtextobject.cpp b/src/gui/text/qtextobject.cpp index 1476a8a58f1..b0e64a6ea3a 100644 --- a/src/gui/text/qtextobject.cpp +++ b/src/gui/text/qtextobject.cpp @@ -1219,7 +1219,7 @@ QString QTextBlock::text() const QTextDocumentPrivate::FragmentIterator end = p->find(pos + length() - 1); // -1 to omit the block separator char for (; it != end; ++it) { const QTextFragmentData * const frag = it.value(); - text += QString::fromRawData(buffer.constData() + frag->stringPosition, frag->size_array[0]); + text += QStringView(buffer.constData() + frag->stringPosition, frag->size_array[0]); } return text;