Add Q_DECL_NOTHROW to some qHash functions
The hashing functions for QDateTime and QHostAddress did not get the noexcept keyword because they might allocate memory. QDateTime doesn't do it now, but it could in the future. QHostAddress does allocate memory today. Change-Id: Ia5f80942944bfc2b8c405306c467bfd88ef0e48c Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
291938aea6
commit
373845dfd8
@ -3445,7 +3445,7 @@ QString QUrl::errorString() const
|
||||
\relates QHash
|
||||
\since 5.0
|
||||
*/
|
||||
uint qHash(const QUrl &url, uint seed)
|
||||
uint qHash(const QUrl &url, uint seed) Q_DECL_NOTHROW
|
||||
{
|
||||
if (!url.d)
|
||||
return qHash(-1, seed); // the hash of an unset port (-1)
|
||||
|
@ -321,7 +321,7 @@ public:
|
||||
static QByteArray toAce(const QString &);
|
||||
static QStringList idnWhitelist();
|
||||
static void setIdnWhitelist(const QStringList &);
|
||||
friend Q_CORE_EXPORT uint qHash(const QUrl &url, uint seed = 0);
|
||||
friend Q_CORE_EXPORT uint qHash(const QUrl &url, uint seed = 0) Q_DECL_NOTHROW;
|
||||
|
||||
private:
|
||||
QUrlPrivate *d;
|
||||
|
@ -1006,7 +1006,7 @@ QDebug operator<<(QDebug dbg, const QUuid &id)
|
||||
\relates QUuid
|
||||
Returns a hash of the UUID \a uuid, using \a seed to seed the calculation.
|
||||
*/
|
||||
uint qHash(const QUuid &uuid, uint seed)
|
||||
uint qHash(const QUuid &uuid, uint seed) Q_DECL_NOTHROW
|
||||
{
|
||||
return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16)
|
||||
^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3])
|
||||
|
@ -227,7 +227,7 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QUuid &);
|
||||
Q_CORE_EXPORT QDebug operator<<(QDebug, const QUuid &);
|
||||
#endif
|
||||
|
||||
Q_CORE_EXPORT uint qHash(const QUuid &uuid, uint seed = 0);
|
||||
Q_CORE_EXPORT uint qHash(const QUuid &uuid, uint seed = 0) Q_DECL_NOTHROW;
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
@ -54,7 +54,7 @@ class Q_CORE_EXPORT QBitArray
|
||||
{
|
||||
friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QBitArray &);
|
||||
friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QBitArray &);
|
||||
friend Q_CORE_EXPORT uint qHash(const QBitArray &key, uint seed);
|
||||
friend Q_CORE_EXPORT uint qHash(const QBitArray &key, uint seed) Q_DECL_NOTHROW;
|
||||
QByteArray d;
|
||||
|
||||
public:
|
||||
|
@ -4097,7 +4097,7 @@ uint qHash(const QDateTime &key, uint seed)
|
||||
|
||||
Returns the hash value for the \a key, using \a seed to seed the calculation.
|
||||
*/
|
||||
uint qHash(const QDate &key, uint seed)
|
||||
uint qHash(const QDate &key, uint seed) Q_DECL_NOTHROW
|
||||
{
|
||||
return qHash(key.toJulianDay(), seed);
|
||||
}
|
||||
@ -4108,9 +4108,9 @@ uint qHash(const QDate &key, uint seed)
|
||||
|
||||
Returns the hash value for the \a key, using \a seed to seed the calculation.
|
||||
*/
|
||||
uint qHash(const QTime &key, uint seed)
|
||||
uint qHash(const QTime &key, uint seed) Q_DECL_NOTHROW
|
||||
{
|
||||
return QTime(0, 0, 0, 0).msecsTo(key) ^ seed;
|
||||
return qHash(QTime(0, 0, 0, 0).msecsTo(key), seed);
|
||||
}
|
||||
|
||||
#ifndef QT_BOOTSTRAPPED
|
||||
|
@ -288,9 +288,11 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QTime &);
|
||||
Q_CORE_EXPORT QDebug operator<<(QDebug, const QDateTime &);
|
||||
#endif
|
||||
|
||||
// QDateTime is not noexcept for now -- to be revised once
|
||||
// timezone and calendaring support is added
|
||||
Q_CORE_EXPORT uint qHash(const QDateTime &key, uint seed = 0);
|
||||
Q_CORE_EXPORT uint qHash(const QDate &key, uint seed = 0);
|
||||
Q_CORE_EXPORT uint qHash(const QTime &key, uint seed = 0);
|
||||
Q_CORE_EXPORT uint qHash(const QDate &key, uint seed = 0) Q_DECL_NOTHROW;
|
||||
Q_CORE_EXPORT uint qHash(const QTime &key, uint seed = 0) Q_DECL_NOTHROW;
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
@ -93,7 +93,7 @@ QT_BEGIN_NAMESPACE
|
||||
(for instance, gcc 4.4 does that even at -O0).
|
||||
*/
|
||||
|
||||
static inline uint hash(const uchar *p, int len, uint seed)
|
||||
static inline uint hash(const uchar *p, int len, uint seed) Q_DECL_NOTHROW
|
||||
{
|
||||
uint h = seed;
|
||||
|
||||
@ -103,7 +103,7 @@ static inline uint hash(const uchar *p, int len, uint seed)
|
||||
return h;
|
||||
}
|
||||
|
||||
static inline uint hash(const QChar *p, int len, uint seed)
|
||||
static inline uint hash(const QChar *p, int len, uint seed) Q_DECL_NOTHROW
|
||||
{
|
||||
uint h = seed;
|
||||
|
||||
@ -113,22 +113,22 @@ static inline uint hash(const QChar *p, int len, uint seed)
|
||||
return h;
|
||||
}
|
||||
|
||||
uint qHash(const QByteArray &key, uint seed)
|
||||
uint qHash(const QByteArray &key, uint seed) Q_DECL_NOTHROW
|
||||
{
|
||||
return hash(reinterpret_cast<const uchar *>(key.constData()), key.size(), seed);
|
||||
}
|
||||
|
||||
uint qHash(const QString &key, uint seed)
|
||||
uint qHash(const QString &key, uint seed) Q_DECL_NOTHROW
|
||||
{
|
||||
return hash(key.unicode(), key.size(), seed);
|
||||
}
|
||||
|
||||
uint qHash(const QStringRef &key, uint seed)
|
||||
uint qHash(const QStringRef &key, uint seed) Q_DECL_NOTHROW
|
||||
{
|
||||
return hash(key.unicode(), key.size(), seed);
|
||||
}
|
||||
|
||||
uint qHash(const QBitArray &bitArray, uint seed)
|
||||
uint qHash(const QBitArray &bitArray, uint seed) Q_DECL_NOTHROW
|
||||
{
|
||||
int m = bitArray.d.size() - 1;
|
||||
uint result = hash(reinterpret_cast<const uchar *>(bitArray.d.constData()), qMax(0, m), seed);
|
||||
@ -141,7 +141,7 @@ uint qHash(const QBitArray &bitArray, uint seed)
|
||||
return result;
|
||||
}
|
||||
|
||||
uint qHash(QLatin1String key, uint seed)
|
||||
uint qHash(QLatin1String key, uint seed) Q_DECL_NOTHROW
|
||||
{
|
||||
return hash(reinterpret_cast<const uchar *>(key.data()), key.size(), seed);
|
||||
}
|
||||
@ -242,7 +242,7 @@ static void qt_initialize_qhash_seed()
|
||||
|
||||
This function must *never* change its results.
|
||||
*/
|
||||
uint qt_hash(const QString &key)
|
||||
uint qt_hash(const QString &key) Q_DECL_NOTHROW
|
||||
{
|
||||
const QChar *p = key.unicode();
|
||||
int n = key.size();
|
||||
|
@ -58,14 +58,14 @@ class QString;
|
||||
class QStringRef;
|
||||
class QLatin1String;
|
||||
|
||||
inline uint qHash(char key, uint seed = 0) { return uint(key) ^ seed; }
|
||||
inline uint qHash(uchar key, uint seed = 0) { return uint(key) ^ seed; }
|
||||
inline uint qHash(signed char key, uint seed = 0) { return uint(key) ^ seed; }
|
||||
inline uint qHash(ushort key, uint seed = 0) { return uint(key) ^ seed; }
|
||||
inline uint qHash(short key, uint seed = 0) { return uint(key) ^ seed; }
|
||||
inline uint qHash(uint key, uint seed = 0) { return key ^ seed; }
|
||||
inline uint qHash(int key, uint seed = 0) { return uint(key) ^ seed; }
|
||||
inline uint qHash(ulong key, uint seed = 0)
|
||||
inline uint qHash(char key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
|
||||
inline uint qHash(uchar key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
|
||||
inline uint qHash(signed char key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
|
||||
inline uint qHash(ushort key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
|
||||
inline uint qHash(short key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
|
||||
inline uint qHash(uint key, uint seed = 0) Q_DECL_NOTHROW { return key ^ seed; }
|
||||
inline uint qHash(int key, uint seed = 0) Q_DECL_NOTHROW { return uint(key) ^ seed; }
|
||||
inline uint qHash(ulong key, uint seed = 0) Q_DECL_NOTHROW
|
||||
{
|
||||
if (sizeof(ulong) > sizeof(uint)) {
|
||||
return uint(((key >> (8 * sizeof(uint) - 1)) ^ key) & (~0U)) ^ seed;
|
||||
@ -73,8 +73,8 @@ inline uint qHash(ulong key, uint seed = 0)
|
||||
return uint(key & (~0U)) ^ seed;
|
||||
}
|
||||
}
|
||||
inline uint qHash(long key, uint seed = 0) { return qHash(ulong(key), seed); }
|
||||
inline uint qHash(quint64 key, uint seed = 0)
|
||||
inline uint qHash(long key, uint seed = 0) Q_DECL_NOTHROW { return qHash(ulong(key), seed); }
|
||||
inline uint qHash(quint64 key, uint seed = 0) Q_DECL_NOTHROW
|
||||
{
|
||||
if (sizeof(quint64) > sizeof(uint)) {
|
||||
return uint(((key >> (8 * sizeof(uint) - 1)) ^ key) & (~0U)) ^ seed;
|
||||
@ -82,20 +82,20 @@ inline uint qHash(quint64 key, uint seed = 0)
|
||||
return uint(key & (~0U)) ^ seed;
|
||||
}
|
||||
}
|
||||
inline uint qHash(qint64 key, uint seed = 0) { return qHash(quint64(key), seed); }
|
||||
inline uint qHash(QChar key, uint seed = 0) { return qHash(key.unicode(), seed); }
|
||||
Q_CORE_EXPORT uint qHash(const QByteArray &key, uint seed = 0);
|
||||
Q_CORE_EXPORT uint qHash(const QString &key, uint seed = 0);
|
||||
Q_CORE_EXPORT uint qHash(const QStringRef &key, uint seed = 0);
|
||||
Q_CORE_EXPORT uint qHash(const QBitArray &key, uint seed = 0);
|
||||
Q_CORE_EXPORT uint qHash(QLatin1String key, uint seed = 0);
|
||||
Q_CORE_EXPORT uint qt_hash(const QString &key);
|
||||
inline uint qHash(qint64 key, uint seed = 0) Q_DECL_NOTHROW { return qHash(quint64(key), seed); }
|
||||
inline uint qHash(QChar key, uint seed = 0) Q_DECL_NOTHROW { return qHash(key.unicode(), seed); }
|
||||
Q_CORE_EXPORT uint qHash(const QByteArray &key, uint seed = 0) Q_DECL_NOTHROW;
|
||||
Q_CORE_EXPORT uint qHash(const QString &key, uint seed = 0) Q_DECL_NOTHROW;
|
||||
Q_CORE_EXPORT uint qHash(const QStringRef &key, uint seed = 0) Q_DECL_NOTHROW;
|
||||
Q_CORE_EXPORT uint qHash(const QBitArray &key, uint seed = 0) Q_DECL_NOTHROW;
|
||||
Q_CORE_EXPORT uint qHash(QLatin1String key, uint seed = 0) Q_DECL_NOTHROW;
|
||||
Q_CORE_EXPORT uint qt_hash(const QString &key) Q_DECL_NOTHROW;
|
||||
|
||||
#if defined(Q_CC_MSVC)
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 4311 ) // disable pointer truncation warning
|
||||
#endif
|
||||
template <class T> inline uint qHash(const T *key, uint seed = 0)
|
||||
template <class T> inline uint qHash(const T *key, uint seed = 0) Q_DECL_NOTHROW
|
||||
{
|
||||
return qHash(reinterpret_cast<quintptr>(key), seed);
|
||||
}
|
||||
@ -103,9 +103,12 @@ template <class T> inline uint qHash(const T *key, uint seed = 0)
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
template<typename T> inline uint qHash(const T &t, uint seed) { return (qHash(t) ^ seed); }
|
||||
template<typename T> inline uint qHash(const T &t, uint seed)
|
||||
Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t)))
|
||||
{ return (qHash(t) ^ seed); }
|
||||
|
||||
template <typename T1, typename T2> inline uint qHash(const QPair<T1, T2> &key, uint seed = 0)
|
||||
Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(key.first, seed)) && noexcept(qHash(key.second, seed)))
|
||||
{
|
||||
uint h1 = qHash(key.first, seed);
|
||||
uint h2 = qHash(key.second, seed);
|
||||
|
@ -1031,6 +1031,7 @@ QDebug operator<<(QDebug d, const QHostAddress &address)
|
||||
|
||||
uint qHash(const QHostAddress &key, uint seed)
|
||||
{
|
||||
// both lines might throw
|
||||
QT_ENSURE_PARSED(&key);
|
||||
return qHash(QByteArray::fromRawData(reinterpret_cast<const char *>(key.d->a6.c), 16), seed);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user