From 83526a9bdc4133e0bc574e0f9223234ea5afe40c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 28 Mar 2012 18:11:12 -0300 Subject: [PATCH] De-inline qHash(const QUrl&) and improve Make it a friend and access the internals to have better performance. Change-Id: I3bbf0b0faa5363278b7b3871d6b6fb5f2225a5f4 Reviewed-by: Giuseppe D'Angelo Reviewed-by: Lars Knoll --- src/corelib/io/qurl.cpp | 21 +++++++++++++++++++++ src/corelib/io/qurl.h | 6 +----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index a716369594..0e897c7cdd 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -2567,6 +2567,27 @@ QString QUrl::errorString() const \internal */ +/*! \fn uint qHash(const QUrl &url) + \relates QHash + + Returns the hash value for the \a url. +*/ +uint qHash(const QUrl &url) +{ + if (!url.d) + return qHash(-1); // the hash of an unset port (-1) + + return qHash(url.d->scheme) ^ + qHash(url.d->userName) ^ + qHash(url.d->password) ^ + qHash(url.d->host) ^ + qHash(url.d->port) ^ + qHash(url.d->path) ^ + qHash(url.d->query) ^ + qHash(url.d->fragment); +} + + // The following code has the following copyright: /* Copyright (C) Research In Motion Limited 2009. All rights reserved. diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h index a118a9d468..5fcbbf0c0c 100644 --- a/src/corelib/io/qurl.h +++ b/src/corelib/io/qurl.h @@ -304,6 +304,7 @@ public: static QByteArray toAce(const QString &); static QStringList idnWhitelist(); static void setIdnWhitelist(const QStringList &); + friend Q_CORE_EXPORT uint qHash(const QUrl &url); private: QUrlPrivate *d; @@ -314,11 +315,6 @@ public: inline DataPtr &data_ptr() { return d; } }; -inline uint qHash(const QUrl &url) -{ - return qHash(url.toString()); -} - Q_DECLARE_TYPEINFO(QUrl, Q_MOVABLE_TYPE); Q_DECLARE_SHARED(QUrl) Q_DECLARE_OPERATORS_FOR_FLAGS(QUrl::ComponentFormattingOptions)