summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qbytearraymatcher.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-01-21 15:02:08 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-01-23 01:06:57 +0000
commit3d3558dc8f0a1885f416b4650037364f4ef11bd4 (patch)
tree33c0a28a52ec17c86057ba4632e68f92bb2266a0 /src/corelib/text/qbytearraymatcher.h
parent3ec587666f89c996cc0a403775c352954d8b804f (diff)
QStaticByteArrayMatcher: fix searching in 2+GiB haystacks
Add a test (same techniques as for the 4+GiB check in tst_qcryptographichash). Takes ~1s to build the 4GiB test data here, and skips when RAM is too low: $ qtbase/tests/auto/corelib/text/qbytearraymatcher/tst_qbytearraymatcher haystacksWithMoreThan4GiBWork [...] QDEBUG : tst_QByteArrayMatcher::haystacksWithMoreThan4GiBWork() created dataset in 891 ms [...] $ (ulimit -v 2000000; qtbase/tests/auto/corelib/text/qbytearraymatcher/tst_qbytearraymatcher haystacksWithMoreThan4GiBWork) ********* Start testing of tst_QByteArrayMatcher ********* [...] SKIP : tst_QByteArrayMatcher::haystacksWithMoreThan4GiBWork() Could not allocate 4GiB plus a couple hundred bytes of RAM. Loc: [/home/marc/Qt/qt5/qtbase/tests/auto/corelib/text/qbytearraymatcher/tst_qbytearraymatcher.cpp(242)] [...] Found during 6.3 API review. [ChangeLog][QtCore][QStaticByteArrayMatcher] Fixed searching in strings with size > 2GiB (on 64-bit platforms). Fixes: QTBUG-100118 Pick-to: 6.3 Change-Id: I1df420965673b5555fef2b75e785954cc50b654f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qbytearraymatcher.h')
-rw-r--r--src/corelib/text/qbytearraymatcher.h21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/corelib/text/qbytearraymatcher.h b/src/corelib/text/qbytearraymatcher.h
index 2a65a257ee..80473c7585 100644
--- a/src/corelib/text/qbytearraymatcher.h
+++ b/src/corelib/text/qbytearraymatcher.h
@@ -99,15 +99,20 @@ class QStaticByteArrayMatcherBase
uchar data[256];
} m_skiptable;
protected:
- explicit constexpr QStaticByteArrayMatcherBase(const char *pattern, uint n) noexcept
+ explicit constexpr QStaticByteArrayMatcherBase(const char *pattern, size_t n) noexcept
: m_skiptable(generate(pattern, n)) {}
// compiler-generated copy/more ctors/assignment operators are ok!
// compiler-generated dtor is ok!
+#if QT_REMOVED_SINCE(6, 3) && QT_POINTER_SIZE != 4
Q_CORE_EXPORT int indexOfIn(const char *needle, uint nlen, const char *haystack, int hlen, int from) const noexcept;
+#endif
+ Q_CORE_EXPORT qsizetype indexOfIn(const char *needle, size_t nlen,
+ const char *haystack, qsizetype hlen,
+ qsizetype from) const noexcept;
private:
- static constexpr Skiptable generate(const char *pattern, uint n) noexcept
+ static constexpr Skiptable generate(const char *pattern, size_t n) noexcept
{
const auto uchar_max = (std::numeric_limits<uchar>::max)();
uchar max = n > uchar_max ? uchar_max : uchar(n);
@@ -143,7 +148,7 @@ private:
}
};
-template <uint N>
+template <size_t N>
class QStaticByteArrayMatcher : QStaticByteArrayMatcherBase
{
char m_pattern[N];
@@ -153,19 +158,19 @@ public:
explicit constexpr QStaticByteArrayMatcher(const char (&patternToMatch)[N]) noexcept
: QStaticByteArrayMatcherBase(patternToMatch, N - 1), m_pattern()
{
- for (uint i = 0; i < N; ++i)
+ for (size_t i = 0; i < N; ++i)
m_pattern[i] = patternToMatch[i];
}
- int indexIn(const QByteArray &haystack, int from = 0) const noexcept
+ qsizetype indexIn(const QByteArray &haystack, qsizetype from = 0) const noexcept
{ return this->indexOfIn(m_pattern, N - 1, haystack.data(), haystack.size(), from); }
- int indexIn(const char *haystack, int hlen, int from = 0) const noexcept
+ qsizetype indexIn(const char *haystack, qsizetype hlen, qsizetype from = 0) const noexcept
{ return this->indexOfIn(m_pattern, N - 1, haystack, hlen, from); }
- QByteArray pattern() const { return QByteArray(m_pattern, int(N - 1)); }
+ QByteArray pattern() const { return QByteArray(m_pattern, qsizetype(N - 1)); }
};
-template <uint N>
+template <size_t N>
constexpr QStaticByteArrayMatcher<N> qMakeStaticByteArrayMatcher(const char (&pattern)[N]) noexcept
{ return QStaticByteArrayMatcher<N>(pattern); }