Update tst_bench_qhash hash functions to use size_t

Pre-requisite for a fix for qHash. The Qt50String inherits from QString
and becomes ambiguous once it no longer goes through a catch-all
template function because qHash(QString, size_t) has a better match for
the second argument.

Change-Id: I23c7afb1b3aa167d40dc4838e82b7763de015f6b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 7fea2d34fb3e9d13deb584595d119c870389b912)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Mårten Nordheim 2022-09-24 13:54:42 +02:00 committed by Qt Cherry-pick Bot
parent 4a9fb8c475
commit ea730ed599
2 changed files with 10 additions and 10 deletions

View File

@ -5,9 +5,9 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
uint qHash(const Qt4String &str) size_t qHash(const Qt4String &str)
{ {
int n = str.length(); qsizetype n = str.length();
const QChar *p = str.unicode(); const QChar *p = str.unicode();
uint h = 0; uint h = 0;
@ -19,11 +19,11 @@ uint qHash(const Qt4String &str)
return h; return h;
} }
uint qHash(const Qt50String &key, uint seed) size_t qHash(const Qt50String &key, size_t seed)
{ {
const QChar *p = key.unicode(); const QChar *p = key.unicode();
int len = key.size(); qsizetype len = key.size();
uint h = seed; size_t h = seed;
for (int i = 0; i < len; ++i) for (int i = 0; i < len; ++i)
h = 31 * h + p[i].unicode(); h = 31 * h + p[i].unicode();
return h; return h;
@ -40,10 +40,10 @@ uint qHash(const Qt50String &key, uint seed)
// Still, we can avoid writing the multiplication as "(h << 5) - h" // Still, we can avoid writing the multiplication as "(h << 5) - h"
// -- the compiler will turn it into a shift and an addition anyway // -- the compiler will turn it into a shift and an addition anyway
// (for instance, gcc 4.4 does that even at -O0). // (for instance, gcc 4.4 does that even at -O0).
uint qHash(const JavaString &str) size_t qHash(const JavaString &str)
{ {
const unsigned short *p = (unsigned short *)str.constData(); const unsigned short *p = (unsigned short *)str.constData();
const int len = str.size(); const qsizetype len = str.size();
uint h = 0; uint h = 0;

View File

@ -10,7 +10,7 @@ struct Qt4String : QString
}; };
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
uint qHash(const Qt4String &); size_t qHash(const Qt4String &);
QT_END_NAMESPACE QT_END_NAMESPACE
struct Qt50String : QString struct Qt50String : QString
@ -20,7 +20,7 @@ struct Qt50String : QString
}; };
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
uint qHash(const Qt50String &, uint seed = 0); size_t qHash(const Qt50String &, size_t seed = 0);
QT_END_NAMESPACE QT_END_NAMESPACE
@ -31,6 +31,6 @@ struct JavaString : QString
}; };
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
uint qHash(const JavaString &); size_t qHash(const JavaString &);
QT_END_NAMESPACE QT_END_NAMESPACE