summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qhash.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-08-02 15:51:52 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-20 21:59:21 +0200
commit373845dfd8acae0c941432c8cd615b77bcae0a2a (patch)
treed8d88bdd6657a18f55456bfe2ac5dfff682e76aa /src/corelib/tools/qhash.h
parent291938aea6771a0ce4c11a164583a73c6eef026e (diff)
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>
Diffstat (limited to 'src/corelib/tools/qhash.h')
-rw-r--r--src/corelib/tools/qhash.h43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 80ed456ace..8e86fd26c1 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -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);