diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index d9c092bb4c3..4f0cd914ca3 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="); diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp index ce7f7b8a0f8..9c54b9ada4d 100644 --- a/src/gui/image/qxpmhandler.cpp +++ b/src/gui/image/qxpmhandler.cpp @@ -42,6 +42,7 @@ #ifndef QT_NO_IMAGEFORMAT_XPM #include +#include #include #include #include @@ -1041,7 +1042,9 @@ bool qt_read_xpm_image_or_array(QIODevice *device, const char * const * source, if ((readBytes = device->readLine(buf.data(), buf.size())) < 0) return false; - if (buf.indexOf("/* XPM") != 0) { + static Q_RELAXED_CONSTEXPR auto matcher = qMakeStaticByteArrayMatcher("/* XPM"); + + if (matcher.indexIn(buf) != 0) { while (readBytes > 0) { device->ungetChar(buf.at(readBytes - 1)); --readBytes; diff --git a/src/plugins/platforms/windows/qwindowsmime.cpp b/src/plugins/platforms/windows/qwindowsmime.cpp index bd4822c664f..eb53dc921b7 100644 --- a/src/plugins/platforms/windows/qwindowsmime.cpp +++ b/src/plugins/platforms/windows/qwindowsmime.cpp @@ -41,6 +41,7 @@ #include "qwindowscontext.h" #include +#include #include #include #include @@ -955,9 +956,11 @@ QVariant QWindowsMimeHtml::convertToMime(const QString &mime, IDataObject *pData QVariant result; if (canConvertToMime(mime, pDataObj)) { QByteArray html = getData(CF_HTML, pDataObj); + static Q_RELAXED_CONSTEXPR auto startMatcher = qMakeStaticByteArrayMatcher("StartHTML:"); + static Q_RELAXED_CONSTEXPR auto endMatcher = qMakeStaticByteArrayMatcher("EndHTML:"); qCDebug(lcQpaMime) << __FUNCTION__ << "raw:" << html; - int start = html.indexOf("StartHTML:"); - int end = html.indexOf("EndHTML:"); + int start = startMatcher.indexIn(html); + int end = endMatcher.indexIn(html); if (start != -1) { int startOffset = start + 10; @@ -997,10 +1000,13 @@ bool QWindowsMimeHtml::convertFromMime(const FORMATETC &formatetc, const QMimeDa "StartFragment:0000000000\r\n" // 56-81 "EndFragment:0000000000\r\n\r\n"; // 82-107 - if (data.indexOf("") == -1) + static Q_RELAXED_CONSTEXPR auto startFragmentMatcher = qMakeStaticByteArrayMatcher(""); + static Q_RELAXED_CONSTEXPR auto endFragmentMatcher = qMakeStaticByteArrayMatcher(""); + + if (startFragmentMatcher.indexIn(data) == -1) result += ""; result += data; - if (data.indexOf("") == -1) + if (endFragmentMatcher.indexIn(data) == -1) result += ""; // set the correct number for EndHTML @@ -1008,9 +1014,9 @@ bool QWindowsMimeHtml::convertFromMime(const FORMATETC &formatetc, const QMimeDa memcpy(reinterpret_cast(result.data() + 53 - pos.length()), pos.constData(), size_t(pos.length())); // set correct numbers for StartFragment and EndFragment - pos = QByteArray::number(result.indexOf("") + 20); + pos = QByteArray::number(startFragmentMatcher.indexIn(result) + 20); memcpy(reinterpret_cast(result.data() + 79 - pos.length()), pos.constData(), size_t(pos.length())); - pos = QByteArray::number(result.indexOf("")); + pos = QByteArray::number(endFragmentMatcher.indexIn(result)); memcpy(reinterpret_cast(result.data() + 103 - pos.length()), pos.constData(), size_t(pos.length())); return setData(result, pmedium);