QHostAddress: improve qHash implementation
Avoid the conversion to a temporary QString -- just hash the address as a byte array. Change-Id: Ic35cdbbc3ee66c32a28d911bd27de0092395979f Done-with: Shane Kearns Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
This commit is contained in:
parent
9166163f10
commit
ea17c21fd8
@ -1029,7 +1029,8 @@ QDebug operator<<(QDebug d, const QHostAddress &address)
|
||||
|
||||
uint qHash(const QHostAddress &key, uint seed)
|
||||
{
|
||||
return qHash(key.toString(), seed);
|
||||
QT_ENSURE_PARSED(&key);
|
||||
return qHash(QByteArray::fromRawData(reinterpret_cast<const char *>(key.d->a6.c), 16), seed);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
|
@ -123,6 +123,7 @@ public:
|
||||
|
||||
static QPair<QHostAddress, int> parseSubnet(const QString &subnet);
|
||||
|
||||
friend Q_NETWORK_EXPORT uint qHash(const QHostAddress &key, uint seed = 0);
|
||||
protected:
|
||||
QScopedPointer<QHostAddressPrivate> d;
|
||||
};
|
||||
@ -134,9 +135,6 @@ inline bool operator ==(QHostAddress::SpecialAddress address1, const QHostAddres
|
||||
Q_NETWORK_EXPORT QDebug operator<<(QDebug, const QHostAddress &);
|
||||
#endif
|
||||
|
||||
|
||||
Q_NETWORK_EXPORT uint qHash(const QHostAddress &key, uint seed = 0);
|
||||
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
Q_NETWORK_EXPORT QDataStream &operator<<(QDataStream &, const QHostAddress &);
|
||||
Q_NETWORK_EXPORT QDataStream &operator>>(QDataStream &, QHostAddress &);
|
||||
|
@ -323,6 +323,8 @@ void tst_QHostAddress::compare()
|
||||
QFETCH(bool, result);
|
||||
|
||||
QCOMPARE(first == second, result);
|
||||
if (result == true)
|
||||
QVERIFY(qHash(first) == qHash(second));
|
||||
}
|
||||
|
||||
void tst_QHostAddress::assignment()
|
||||
|
Loading…
Reference in New Issue
Block a user