We must do this the same way we do all other hash algorithms for fair
comparison, as otherwise, the call to the PLT unfairly penalises
QHash<QString>'s results, as it's in a different shared object.
Change-Id: I69c891f5a97dcccdfcfbdbf32796f86242a42963
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
void tst_QHash::qhash_qt4()
{
QFETCH(QStringList, items);
- QStringList realitems = items; // for copy/paste ease between benchmarks
- QHash<QString, int> hash;
+ QHash<Qt4String, int> hash;
+
+ QList<Qt4String> realitems;
+ foreach (const QString &s, items)
+ realitems.append(s);
QBENCHMARK {
for (int i = 0, n = realitems.size(); i != n; ++i) {
#include <QString>
+struct Qt4String : QString
+{
+ Qt4String() {}
+ Qt4String(const QString &s) : QString(s) {}
+};
+
+QT_BEGIN_NAMESPACE
+uint qHash(const Qt4String &);
+QT_END_NAMESPACE
+
+
struct String : QString
{
String() {}
#include "main.h"
+QT_BEGIN_NAMESPACE
+
+uint qHash(const Qt4String &str)
+{
+ int n = str.length();
+ const QChar *p = str.unicode();
+ uint h = 0;
+
+ while (n--) {
+ h = (h << 4) + (*p++).unicode();
+ h ^= (h & 0xf0000000) >> 23;
+ h &= 0x0fffffff;
+ }
+ return h;
+}
+
static void doHash(const unsigned short *p, uint &h)
{
#if 1
#endif
}
-QT_BEGIN_NAMESPACE
-
uint qHash(const String &str)
{
const unsigned short *p = (unsigned short *)str.constData();