summaryrefslogtreecommitdiffstats
path: root/src/corelib/text
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2024-02-28 09:06:05 -0800
committerThiago Macieira <thiago.macieira@intel.com>2024-03-04 11:31:48 -0800
commita6b4ff16b9f6ba7f93d55c0eedb5ef44f2d85c99 (patch)
tree37495bf3d720bce7848369bc9c76708c0b1fcede /src/corelib/text
parenta14bba6803f674edede596eaeb5a46feed0f889e (diff)
Replace some QString::fromUtf16() with QStringView::toString()
The QStringView counterpart is somewhat faster because it doesn't go through the UTF-16 codec in QUtf16::convertToUnicode(), which tries to detect the BOM. I've included QString::fromWCharArray in this because: a) it's used extensively in Windows code b) wide chars in memory probably don't have BOMs anyway Change-Id: I01ec3c774d9943adb903fffd17b815be4d2ab8ba Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Diffstat (limited to 'src/corelib/text')
-rw-r--r--src/corelib/text/qregularexpression.cpp2
-rw-r--r--src/corelib/text/qstring.h7
2 files changed, 6 insertions, 3 deletions
diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp
index a1e288ae6c..95fd0e3d9a 100644
--- a/src/corelib/text/qregularexpression.cpp
+++ b/src/corelib/text/qregularexpression.cpp
@@ -1508,7 +1508,7 @@ QStringList QRegularExpression::namedCaptureGroups() const
reinterpret_cast<const char16_t *>(namedCapturingTable) + namedCapturingTableEntrySize * i;
const int index = *currentNamedCapturingTableRow;
- result[index] = QString::fromUtf16(currentNamedCapturingTableRow + 1);
+ result[index] = QStringView(currentNamedCapturingTableRow + 1).toString();
}
return result;
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index e2a6605861..a76909c081 100644
--- a/src/corelib/text/qstring.h
+++ b/src/corelib/text/qstring.h
@@ -1307,8 +1307,11 @@ QT_WARNING_POP
QString QString::fromWCharArray(const wchar_t *string, qsizetype size)
{
- return sizeof(wchar_t) == sizeof(QChar) ? fromUtf16(reinterpret_cast<const char16_t *>(string), size)
- : fromUcs4(reinterpret_cast<const char32_t *>(string), size);
+ if constexpr (sizeof(wchar_t) == sizeof(QChar)) {
+ return QString(reinterpret_cast<const QChar *>(string), size);
+ } else {
+ return fromUcs4(reinterpret_cast<const char32_t *>(string), size);
+ }
}
constexpr QString::QString() noexcept {}