diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-01-24 09:26:54 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-01-24 21:11:22 +0100 |
commit | af2d9bc3c46818f2b99056e5407493f0830dab3b (patch) | |
tree | f88e7f81ea0f6ae5bbdde7eca31ec584f8e0f59e | |
parent | d1639da0d593642f65558e323da6f6d54bc65f3b (diff) |
Optimize finding UTF-16 needles in L1 haystacks
We were converting the full L1 haystack to UTF-16. But, even so, we
won't be able to find non-L1 UTF-16 needles in L1 haystacks!
Optimize by converting the needle (not the haystack) to L1, after
checking it's actually L1.
Pick-to: 6.3
Change-Id: I413d7a602d44ecb2d3149dc4fa87c690c40e6aaa
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r-- | src/corelib/text/qstring.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 7a908cfd98..a8482c5fbd 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -10508,9 +10508,12 @@ qsizetype QtPrivate::findString(QLatin1String haystack, qsizetype from, QStringV if (haystack.size() < needle.size()) return -1; - QVarLengthArray<char16_t> s(haystack.size()); - qt_from_latin1(s.data(), haystack.latin1(), haystack.size()); - return QtPrivate::findString(QStringView(reinterpret_cast<const QChar*>(s.constData()), s.size()), from, needle, cs); + if (!QtPrivate::isLatin1(needle)) // won't find non-L1 UTF-16 needles in a L1 haystack! + return -1; + + QVarLengthArray<char> s(needle.size()); + qt_to_latin1_unchecked(reinterpret_cast<uchar *>(s.data()), needle.utf16(), needle.size()); + return QtPrivate::findString(haystack, from, QLatin1String(s.data(), s.size()), cs); } qsizetype QtPrivate::findString(QLatin1String haystack, qsizetype from, QLatin1String needle, Qt::CaseSensitivity cs) noexcept |