QByteArray: inline the REHASH macro into the code

It was used in a single place, in each of these files, now that the
forward indexOf is moved to qbytearraymatcher.cpp. There's another copy
in qstring.cpp.

Task-number: QTBUG-125283
Change-Id: If05cb740b64f42eba21efffd17cf30607317877a
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
bb10
Thiago Macieira 2024-05-13 16:32:53 -07:00
parent 726379c581
commit 7886d0adbb
2 changed files with 6 additions and 18 deletions

View File

@ -2676,11 +2676,6 @@ QByteArray QByteArray::repeated(qsizetype times) const
return result;
}
#define REHASH(a) \
if (ol_minus_1 < sizeof(std::size_t) * CHAR_BIT) \
hashHaystack -= std::size_t(a) << ol_minus_1; \
hashHaystack <<= 1
/*! \fn qsizetype QByteArray::indexOf(QByteArrayView bv, qsizetype from) const
\since 6.0
@ -2736,10 +2731,11 @@ static qsizetype lastIndexOfHelper(const char *haystack, qsizetype l, const char
if (hashHaystack == hashNeedle && memcmp(needle, haystack, ol) == 0)
return haystack - end;
--haystack;
REHASH(*(haystack + ol));
if (ol_minus_1 < sizeof(std::size_t) * CHAR_BIT)
hashHaystack -= std::size_t(*(haystack + ol)) << ol_minus_1;
hashHaystack <<= 1;
}
return -1;
}
static inline qsizetype lastIndexOfCharHelper(QByteArrayView haystack, qsizetype from, char needle) noexcept
@ -5182,5 +5178,3 @@ size_t qHash(const QByteArray::FromBase64Result &key, size_t seed) noexcept
*/
QT_END_NAMESPACE
#undef REHASH

View File

@ -228,11 +228,6 @@ static qsizetype qFindByteArrayBoyerMoore(
(const uchar *)needle, needleLen, skiptable);
}
#define REHASH(a) \
if (sl_minus_1 < sizeof(std::size_t) * CHAR_BIT) \
hashHaystack -= std::size_t(a) << sl_minus_1; \
hashHaystack <<= 1
/*!
\internal
*/
@ -290,7 +285,9 @@ qsizetype qFindByteArray(const char *haystack0, qsizetype l, qsizetype from,
&& memcmp(needle, haystack, sl) == 0)
return haystack - haystack0;
REHASH(*haystack);
if (sl_minus_1 < sizeof(std::size_t) * CHAR_BIT)
hashHaystack -= std::size_t(*haystack) << sl_minus_1;
hashHaystack <<= 1;
++haystack;
}
return -1;
@ -398,7 +395,4 @@ qsizetype QStaticByteArrayMatcherBase::indexOfIn(const char *needle, size_t nlen
\snippet code/src_corelib_text_qbytearraymatcher.cpp 1
*/
QT_END_NAMESPACE
#undef REHASH