summaryrefslogtreecommitdiffstats
path: root/src/corelib/codecs
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-02-25 03:54:13 +0100
committerMarc Mutz <marc.mutz@kdab.com>2017-04-24 18:51:52 +0000
commitbfcc2902a4f4f3d062962e3ba7bf19158d1f56d5 (patch)
tree2f05d2731a5672a67ef987bc4c31860331969c08 /src/corelib/codecs
parent93570810d8813691e4f8b7ade34b0f085c6f0b8d (diff)
QtBase: use new QStaticByteArrayMatcher where applicable
Even for compilers that don't yet support C++14 constexpr, this should improve performance of searches a lot, if, indeed, Boyer-Moore still is an optimization over linear searching at all in these days of hardware prefetchers and deep CPU pipelines, because the setup cost is only incurred once. As function-statics, we also don't care about startup ordering and cost. It's a pity that the platform that would benefit the most - Windows - doesn't have constexpr support, yet. Change-Id: I827df135854fd6fbd6546e248dc37ef0fbaf1792 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Diffstat (limited to 'src/corelib/codecs')
-rw-r--r--src/corelib/codecs/qtextcodec.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp
index d9c092bb4c..4f0cd914ca 100644
--- a/src/corelib/codecs/qtextcodec.cpp
+++ b/src/corelib/codecs/qtextcodec.cpp
@@ -43,6 +43,7 @@
#ifndef QT_NO_TEXTCODEC
+#include "qbytearraymatcher.h"
#include "qlist.h"
#include "qfile.h"
#include "qstringlist.h"
@@ -1092,10 +1093,12 @@ QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba, QTextCodec *defaultCo
// determine charset
QTextCodec *c = QTextCodec::codecForUtfText(ba, 0);
if (!c) {
+ static Q_RELAXED_CONSTEXPR auto matcher = qMakeStaticByteArrayMatcher("meta ");
QByteArray header = ba.left(1024).toLower();
- int pos = header.indexOf("meta ");
+ int pos = matcher.indexIn(header);
if (pos != -1) {
- pos = header.indexOf("charset=", pos);
+ static Q_RELAXED_CONSTEXPR auto matcher = qMakeStaticByteArrayMatcher("charset=");
+ pos = matcher.indexIn(header, pos);
if (pos != -1) {
pos += qstrlen("charset=");