Bug 1119199 - Rewrite HashFunctions with variadic templates. r=waldo
authorXidorn Quan <quanxunzhen@gmail.com>
Tue, 13 Jan 2015 10:48:10 +1100
changeset 223450 428abebd41a3ca23e0f53ee6379b4b71da6d5270
parent 223449 accc4cc9009e9611db97e2f84ede0383ad1b6777
child 223451 7de37d6b2f4c345bb212ad57b237d398101086b7
push id28095
push usercbook@mozilla.com
push dateTue, 13 Jan 2015 13:24:48 +0000
treeherdermozilla-central@a5700bec72e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs1119199
milestone38.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 1119199 - Rewrite HashFunctions with variadic templates. r=waldo
mfbt/HashFunctions.h
--- a/mfbt/HashFunctions.h
+++ b/mfbt/HashFunctions.h
@@ -182,84 +182,35 @@ AddToHash(uint32_t aHash, A* aA)
 
 template<>
 MOZ_WARN_UNUSED_RESULT inline uint32_t
 AddToHash(uint32_t aHash, uintptr_t aA)
 {
   return detail::AddUintptrToHash<sizeof(uintptr_t)>(aHash, aA);
 }
 
-template<typename A, typename B>
+template<typename A, typename... Args>
 MOZ_WARN_UNUSED_RESULT uint32_t
-AddToHash(uint32_t aHash, A aA, B aB)
-{
-  return AddToHash(AddToHash(aHash, aA), aB);
-}
-
-template<typename A, typename B, typename C>
-MOZ_WARN_UNUSED_RESULT uint32_t
-AddToHash(uint32_t aHash, A aA, B aB, C aC)
+AddToHash(uint32_t aHash, A aArg, Args... aArgs)
 {
-  return AddToHash(AddToHash(aHash, aA, aB), aC);
-}
-
-template<typename A, typename B, typename C, typename D>
-MOZ_WARN_UNUSED_RESULT uint32_t
-AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD)
-{
-  return AddToHash(AddToHash(aHash, aA, aB, aC), aD);
-}
-
-template<typename A, typename B, typename C, typename D, typename E>
-MOZ_WARN_UNUSED_RESULT uint32_t
-AddToHash(uint32_t aHash, A aA, B aB, C aC, D aD, E aE)
-{
-  return AddToHash(AddToHash(aHash, aA, aB, aC, aD), aE);
+  return AddToHash(AddToHash(aHash, aArg), aArgs...);
 }
 
 /**
  * The HashGeneric class of functions let you hash one or more values.
  *
  * If you want to hash together two values x and y, calling HashGeneric(x, y) is
  * much better than calling AddToHash(x, y), because AddToHash(x, y) assumes
  * that x has already been hashed.
  */
-template<typename A>
-MOZ_WARN_UNUSED_RESULT inline uint32_t
-HashGeneric(A aA)
-{
-  return AddToHash(0, aA);
-}
-
-template<typename A, typename B>
-MOZ_WARN_UNUSED_RESULT inline uint32_t
-HashGeneric(A aA, B aB)
-{
-  return AddToHash(0, aA, aB);
-}
-
-template<typename A, typename B, typename C>
+template<typename... Args>
 MOZ_WARN_UNUSED_RESULT inline uint32_t
-HashGeneric(A aA, B aB, C aC)
-{
-  return AddToHash(0, aA, aB, aC);
-}
-
-template<typename A, typename B, typename C, typename D>
-MOZ_WARN_UNUSED_RESULT inline uint32_t
-HashGeneric(A aA, B aB, C aC, D aD)
+HashGeneric(Args... aArgs)
 {
-  return AddToHash(0, aA, aB, aC, aD);
-}
-
-template<typename A, typename B, typename C, typename D, typename E>
-MOZ_WARN_UNUSED_RESULT inline uint32_t
-HashGeneric(A aA, B aB, C aC, D aD, E aE)
-{
-  return AddToHash(0, aA, aB, aC, aD, aE);
+  return AddToHash(0, aArgs...);
 }
 
 namespace detail {
 
 template<typename T>
 uint32_t
 HashUntilZero(const T* aStr)
 {