From bfcc2902a4f4f3d062962e3ba7bf19158d1f56d5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 25 Feb 2016 03:54:13 +0100 Subject: 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 Reviewed-by: Milian Wolff --- src/corelib/codecs/qtextcodec.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/corelib/codecs') 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="); -- cgit v1.2.3