diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-02-25 03:54:13 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-04-24 18:51:52 +0000 |
commit | bfcc2902a4f4f3d062962e3ba7bf19158d1f56d5 (patch) | |
tree | 2f05d2731a5672a67ef987bc4c31860331969c08 /src/plugins/platforms/windows/qwindowsmime.cpp | |
parent | 93570810d8813691e4f8b7ade34b0f085c6f0b8d (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/plugins/platforms/windows/qwindowsmime.cpp')
-rw-r--r-- | src/plugins/platforms/windows/qwindowsmime.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/plugins/platforms/windows/qwindowsmime.cpp b/src/plugins/platforms/windows/qwindowsmime.cpp index bd4822c664..eb53dc921b 100644 --- a/src/plugins/platforms/windows/qwindowsmime.cpp +++ b/src/plugins/platforms/windows/qwindowsmime.cpp @@ -41,6 +41,7 @@ #include "qwindowscontext.h" #include <QtGui/private/qdnd_p.h> +#include <QtCore/QByteArrayMatcher> #include <QtCore/QTextCodec> #include <QtCore/QMap> #include <QtCore/QUrl> @@ -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("<!--StartFragment-->") == -1) + static Q_RELAXED_CONSTEXPR auto startFragmentMatcher = qMakeStaticByteArrayMatcher("<!--StartFragment-->"); + static Q_RELAXED_CONSTEXPR auto endFragmentMatcher = qMakeStaticByteArrayMatcher("<!--EndFragment-->"); + + if (startFragmentMatcher.indexIn(data) == -1) result += "<!--StartFragment-->"; result += data; - if (data.indexOf("<!--EndFragment-->") == -1) + if (endFragmentMatcher.indexIn(data) == -1) result += "<!--EndFragment-->"; // set the correct number for EndHTML @@ -1008,9 +1014,9 @@ bool QWindowsMimeHtml::convertFromMime(const FORMATETC &formatetc, const QMimeDa memcpy(reinterpret_cast<char *>(result.data() + 53 - pos.length()), pos.constData(), size_t(pos.length())); // set correct numbers for StartFragment and EndFragment - pos = QByteArray::number(result.indexOf("<!--StartFragment-->") + 20); + pos = QByteArray::number(startFragmentMatcher.indexIn(result) + 20); memcpy(reinterpret_cast<char *>(result.data() + 79 - pos.length()), pos.constData(), size_t(pos.length())); - pos = QByteArray::number(result.indexOf("<!--EndFragment-->")); + pos = QByteArray::number(endFragmentMatcher.indexIn(result)); memcpy(reinterpret_cast<char *>(result.data() + 103 - pos.length()), pos.constData(), size_t(pos.length())); return setData(result, pmedium); |