From e1318b1d03725bda7bf8c9f76959007e2f6067d8 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 16 Apr 2018 08:37:15 +1000 Subject: [PATCH] Bug 1451278 - Remove ConstExpr hash functions. r=froydnj MozReview-Commit-ID: L6yRyt4DZRR --HG-- extra : rebase_source : 2d56a50b1a99e66c397165b9b851e23ca66d97a0 --- mfbt/HashFunctions.h | 33 ++++----------------------------- xpcom/ds/nsAtom.h | 2 +- 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/mfbt/HashFunctions.h b/mfbt/HashFunctions.h index 737e322844e0..ad7b708ceef7 100644 --- a/mfbt/HashFunctions.h +++ b/mfbt/HashFunctions.h @@ -210,29 +210,16 @@ HashGeneric(Args... aArgs) namespace detail { template -uint32_t +constexpr uint32_t HashUntilZero(const T* aStr) { uint32_t hash = 0; - for (T c; (c = *aStr); aStr++) { + for (; T c = *aStr; aStr++) { hash = AddToHash(hash, c); } return hash; } -// This is a `constexpr` alternative to HashUntilZero(const T*). It should -// only be used for compile-time computation because it uses recursion. -// XXX: once support for GCC 4.9 is dropped, this function should be removed -// and HashUntilZero(const T*) should be made `constexpr`. -template -constexpr uint32_t -ConstExprHashUntilZero(const T* aStr, uint32_t aHash) -{ - return !*aStr - ? aHash - : ConstExprHashUntilZero(aStr + 1, AddToHash(aHash, *aStr)); -} - template uint32_t HashKnownLength(const T* aStr, size_t aLength) @@ -271,25 +258,13 @@ HashString(const unsigned char* aStr, size_t aLength) return detail::HashKnownLength(aStr, aLength); } -MOZ_MUST_USE inline uint32_t -HashString(const char16_t* aStr) -{ - return detail::HashUntilZero(aStr); -} - -// This is a `constexpr` alternative to HashString(const char16_t*). It should -// only be used for compile-time computation because it uses recursion. -// // You may need to use the // MOZ_{PUSH,POP}_DISABLE_INTEGRAL_CONSTANT_OVERFLOW_WARNING macros if you use // this function. See the comment on those macros' definitions for more detail. -// -// XXX: once support for GCC 4.9 is dropped, this function should be removed -// and HashString(const char16_t*) should be made `constexpr`. MOZ_MUST_USE constexpr uint32_t -ConstExprHashString(const char16_t* aStr) +HashString(const char16_t* aStr) { - return detail::ConstExprHashUntilZero(aStr, 0); + return detail::HashUntilZero(aStr); } MOZ_MUST_USE inline uint32_t diff --git a/xpcom/ds/nsAtom.h b/xpcom/ds/nsAtom.h index 7fb9f4fe97b1..b4999e5f9f7e 100644 --- a/xpcom/ds/nsAtom.h +++ b/xpcom/ds/nsAtom.h @@ -107,7 +107,7 @@ protected: constexpr nsAtom(const char16_t* aStr, uint32_t aLength) : mLength(aLength) , mKind(static_cast(nsAtom::AtomKind::Static)) - , mHash(mozilla::ConstExprHashString(aStr)) + , mHash(mozilla::HashString(aStr)) {} // Used by nsDynamicAtom.