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>bb10
parent
d1639da0d5
commit
af2d9bc3c4
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue