From 75188ee1856a4f87f775fbec8652b971288f29d6 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sat, 1 Mar 2014 14:20:44 +0100 Subject: [PATCH] Fix the qHash(quint64) overload The body doesn't make sense as the if condition is always true (we even have static asserts checking that sizeof(int) == 4). Removing the if allows us to mark the function as constexpr. Change-Id: Iddeb042a6164d4afe6c827c10177596424d770eb Reviewed-by: Thiago Macieira Reviewed-by: Marc Mutz --- src/corelib/tools/qhash.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 0366c1d831..6c34685070 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -78,15 +78,11 @@ Q_DECL_CONST_FUNCTION inline uint qHash(ulong key, uint seed = 0) Q_DECL_NOTHROW } } Q_DECL_CONST_FUNCTION inline uint qHash(long key, uint seed = 0) Q_DECL_NOTHROW { return qHash(ulong(key), seed); } -Q_DECL_CONST_FUNCTION inline uint qHash(quint64 key, uint seed = 0) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR 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; - } else { - return uint(key & (~0U)) ^ seed; - } + return uint(((key >> (8 * sizeof(uint) - 1)) ^ key) & (~0U)) ^ seed; } -Q_DECL_CONST_FUNCTION inline uint qHash(qint64 key, uint seed = 0) Q_DECL_NOTHROW { return qHash(quint64(key), seed); } +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(qint64 key, uint seed = 0) Q_DECL_NOTHROW { return qHash(quint64(key), seed); } Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(float key, uint seed = 0) Q_DECL_NOTHROW; Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(double key, uint seed = 0) Q_DECL_NOTHROW; #ifndef Q_OS_DARWIN