Bug 1451278 - Remove ConstExpr hash functions. r=froydnj
☠☠ backed out by 6a87ef9c1acc ☠ ☠
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 16 Apr 2018 08:37:15 +1000
changeset 467359 5944ccd5060dc8c363b0b46bf6473348c7a09c13
parent 467358 1256e4bb644c28ba235d4050d8ebc8386cf14765
child 467360 ac685df07bfc81d80f81e40d7cac55cbf56d84c1
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1451278
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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 = *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)
   {