Bug 1451278 - Remove ConstExpr hash functions. r=froydnj draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 05 Apr 2018 09:01:40 +1000
changeset 777582 5c33f60e0e4c8e38d3f79d1514bbdd6be7c00bcc
parent 776622 7d7010443cce082bdd0ddc7db0f0d5c78a1d3f5e
child 777583 389c76d78a01ab3bf2957092fe5e6dee5f25964f
push id105253
push usernnethercote@mozilla.com
push dateThu, 05 Apr 2018 01:37:08 +0000
reviewersfroydnj
bugs1451278
milestone61.0a1
Bug 1451278 - Remove ConstExpr hash functions. r=froydnj MozReview-Commit-ID: L6yRyt4DZRR
mfbt/HashFunctions.h
xpcom/ds/nsAtom.h
--- a/mfbt/HashFunctions.h
+++ b/mfbt/HashFunctions.h
@@ -205,39 +205,26 @@ MOZ_MUST_USE inline uint32_t
 HashGeneric(Args... aArgs)
 {
   return AddToHash(0, aArgs...);
 }
 
 namespace detail {
 
 template<typename T>
-uint32_t
+constexpr uint32_t
 HashUntilZero(const T* aStr)
 {
   uint32_t hash = 0;
-  for (T c; (c = *aStr); aStr++) {
+  for (T c = 0; (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<typename T>
-constexpr uint32_t
-ConstExprHashUntilZero(const T* aStr, uint32_t aHash)
-{
-  return !*aStr
-       ? aHash
-       : ConstExprHashUntilZero(aStr + 1, AddToHash(aHash, *aStr));
-}
-
 template<typename T>
 uint32_t
 HashKnownLength(const T* aStr, size_t aLength)
 {
   uint32_t hash = 0;
   for (size_t i = 0; i < aLength; i++) {
     hash = AddToHash(hash, aStr[i]);
   }
@@ -266,37 +253,25 @@ HashString(const char* aStr, size_t aLen
 
 MOZ_MUST_USE
 inline uint32_t
 HashString(const unsigned char* aStr, size_t aLength)
 {
   return detail::HashKnownLength(aStr, aLength);
 }
 
-MOZ_MUST_USE inline uint32_t
+// 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.
+MOZ_MUST_USE constexpr 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)
-{
-  return detail::ConstExprHashUntilZero(aStr, 0);
-}
-
 MOZ_MUST_USE inline uint32_t
 HashString(const char16_t* aStr, size_t aLength)
 {
   return detail::HashKnownLength(aStr, aLength);
 }
 
 /*
  * On Windows, wchar_t is not the same as char16_t, even though it's
--- a/xpcom/ds/nsAtom.h
+++ b/xpcom/ds/nsAtom.h
@@ -102,17 +102,17 @@ public:
 
   typedef mozilla::TrueType HasThreadSafeRefCnt;
 
 protected:
   // Used by nsStaticAtom.
   constexpr nsAtom(const char16_t* aStr, uint32_t aLength)
     : mLength(aLength)
     , mKind(static_cast<uint32_t>(nsAtom::AtomKind::Static))
-    , mHash(mozilla::ConstExprHashString(aStr))
+    , mHash(mozilla::HashString(aStr))
   {}
 
   // Used by nsDynamicAtom.
   nsAtom(AtomKind aKind, const nsAString& aString, uint32_t aHash)
     : mLength(aString.Length())
     , mKind(static_cast<uint32_t>(aKind))
     , mHash(aHash)
   {