QByteArray/QString: use qregisteruint for storing the moving hash
There are some architectures where sizeof(qregisteruint) > sizeof(size_t) so this could be a minor performance improvement. Change-Id: If05cb740b64f42eba21efffd17cf30c3ae5bd88f Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>bb10
parent
7886d0adbb
commit
817c0c33e1
|
|
@ -2716,10 +2716,10 @@ static qsizetype lastIndexOfHelper(const char *haystack, qsizetype l, const char
|
|||
|
||||
const char *end = haystack;
|
||||
haystack += from;
|
||||
const auto ol_minus_1 = std::size_t(ol - 1);
|
||||
const qregisteruint ol_minus_1 = ol - 1;
|
||||
const char *n = needle + ol_minus_1;
|
||||
const char *h = haystack + ol_minus_1;
|
||||
std::size_t hashNeedle = 0, hashHaystack = 0;
|
||||
qregisteruint hashNeedle = 0, hashHaystack = 0;
|
||||
qsizetype idx;
|
||||
for (idx = 0; idx < ol; ++idx) {
|
||||
hashNeedle = ((hashNeedle<<1) + *(n-idx));
|
||||
|
|
@ -2731,8 +2731,8 @@ static qsizetype lastIndexOfHelper(const char *haystack, qsizetype l, const char
|
|||
if (hashHaystack == hashNeedle && memcmp(needle, haystack, ol) == 0)
|
||||
return haystack - end;
|
||||
--haystack;
|
||||
if (ol_minus_1 < sizeof(std::size_t) * CHAR_BIT)
|
||||
hashHaystack -= std::size_t(*(haystack + ol)) << ol_minus_1;
|
||||
if (ol_minus_1 < sizeof(ol_minus_1) * CHAR_BIT)
|
||||
hashHaystack -= qregisteruint(*(haystack + ol)) << ol_minus_1;
|
||||
hashHaystack <<= 1;
|
||||
}
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -270,8 +270,8 @@ qsizetype qFindByteArray(const char *haystack0, qsizetype l, qsizetype from,
|
|||
*/
|
||||
const char *haystack = haystack0 + from;
|
||||
const char *end = haystack0 + (l - sl);
|
||||
const auto sl_minus_1 = std::size_t(sl - 1);
|
||||
std::size_t hashNeedle = 0, hashHaystack = 0;
|
||||
const qregisteruint sl_minus_1 = sl - 1;
|
||||
qregisteruint hashNeedle = 0, hashHaystack = 0;
|
||||
qsizetype idx;
|
||||
for (idx = 0; idx < sl; ++idx) {
|
||||
hashNeedle = ((hashNeedle<<1) + needle[idx]);
|
||||
|
|
@ -285,8 +285,8 @@ qsizetype qFindByteArray(const char *haystack0, qsizetype l, qsizetype from,
|
|||
&& memcmp(needle, haystack, sl) == 0)
|
||||
return haystack - haystack0;
|
||||
|
||||
if (sl_minus_1 < sizeof(std::size_t) * CHAR_BIT)
|
||||
hashHaystack -= std::size_t(*haystack) << sl_minus_1;
|
||||
if (sl_minus_1 < sizeof(sl_minus_1) * CHAR_BIT)
|
||||
hashHaystack -= qregisteruint(*haystack) << sl_minus_1;
|
||||
hashHaystack <<= 1;
|
||||
++haystack;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@
|
|||
#endif
|
||||
|
||||
#define REHASH(a) \
|
||||
if (sl_minus_1 < sizeof(std::size_t) * CHAR_BIT) \
|
||||
hashHaystack -= std::size_t(a) << sl_minus_1; \
|
||||
if (sl_minus_1 < sizeof(sl_minus_1) * CHAR_BIT) \
|
||||
hashHaystack -= decltype(hashHaystack)(a) << sl_minus_1; \
|
||||
hashHaystack <<= 1
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
|
@ -183,10 +183,10 @@ static qsizetype qLastIndexOf(Haystack haystack0, qsizetype from,
|
|||
const auto needle = needle0.data();
|
||||
const auto *end = haystack;
|
||||
haystack += from;
|
||||
const std::size_t sl_minus_1 = sl ? sl - 1 : 0;
|
||||
const qregisteruint sl_minus_1 = sl ? sl - 1 : 0;
|
||||
const auto *n = needle + sl_minus_1;
|
||||
const auto *h = haystack + sl_minus_1;
|
||||
std::size_t hashNeedle = 0, hashHaystack = 0;
|
||||
qregisteruint hashNeedle = 0, hashHaystack = 0;
|
||||
|
||||
if (cs == Qt::CaseSensitive) {
|
||||
for (qsizetype idx = 0; idx < sl; ++idx) {
|
||||
|
|
@ -9905,8 +9905,8 @@ qsizetype QtPrivate::findString(QStringView haystack0, qsizetype from, QStringVi
|
|||
const char16_t *needle = needle0.utf16();
|
||||
const char16_t *haystack = haystack0.utf16() + from;
|
||||
const char16_t *end = haystack0.utf16() + (l - sl);
|
||||
const std::size_t sl_minus_1 = sl - 1;
|
||||
std::size_t hashNeedle = 0, hashHaystack = 0;
|
||||
const qregisteruint sl_minus_1 = sl - 1;
|
||||
qregisteruint hashNeedle = 0, hashHaystack = 0;
|
||||
qsizetype idx;
|
||||
|
||||
if (cs == Qt::CaseSensitive) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue