summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-01-21 00:56:05 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-01-21 21:45:11 +0100
commite7115b75306144ed8fd19dd96da605a3d359489c (patch)
tree001133cd630043d53d0fc1a9370cf218672655d0 /src
parentf091f371c486e04fed0b1083c163b1c2baaf028c (diff)
QStringConverter: use QStaticByteArrayMatcher
The Boyer-Moore tables can be calculated at compile-time, and the needles are long enough to make skipping worthwhile, even for small haystacks. Pick-to: 6.3 Change-Id: I3237812490367ed0491eb8d1667c6da67f38c517 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qstringconverter.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/corelib/text/qstringconverter.cpp b/src/corelib/text/qstringconverter.cpp
index db159738b1..95e49da32b 100644
--- a/src/corelib/text/qstringconverter.cpp
+++ b/src/corelib/text/qstringconverter.cpp
@@ -1809,10 +1809,13 @@ std::optional<QStringConverter::Encoding> QStringConverter::encodingForHtml(QByt
// trust the initial BOM
return encoding;
+ static constexpr auto metaSearcher = qMakeStaticByteArrayMatcher("meta ");
+ static constexpr auto charsetSearcher = qMakeStaticByteArrayMatcher("charset=");
+
QByteArray header = data.first(qMin(data.size(), qsizetype(1024))).toByteArray().toLower();
- qsizetype pos = header.indexOf("meta ");
+ qsizetype pos = metaSearcher.indexIn(header);
if (pos != -1) {
- pos = header.indexOf("charset=", pos);
+ pos = charsetSearcher.indexIn(header, pos);
if (pos != -1) {
pos += int(qstrlen("charset="));
if (pos < header.size() && (header.at(pos) == '\"' || header.at(pos) == '\''))