Bug 1451278 - Remove ConstExpr hash functions. r=froydnj

MozReview-Commit-ID: L6yRyt4DZRR

--HG--
extra : rebase_source : 2d56a50b1a99e66c397165b9b851e23ca66d97a0
This commit is contained in:
Nicholas Nethercote 2018-04-16 08:37:15 +10:00
Родитель e1b9a0b9c4
Коммит e1318b1d03
2 изменённых файлов: 5 добавлений и 30 удалений

Просмотреть файл

@ -210,29 +210,16 @@ HashGeneric(Args... 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)
@ -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

Просмотреть файл

@ -107,7 +107,7 @@ protected:
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.