Bug 1119199 - Rewrite HashFunctions with variadic templates. r=waldo
authorXidorn Quan <quanxunzhen@gmail.com>
Tue, 13 Jan 2015 10:48:10 +1100
changeset 223423 428abebd41a3
parent 223422 accc4cc9009e
child 223424 7de37d6b2f4c
push id53905
push userxquan@mozilla.com
push dateMon, 12 Jan 2015 23:48:49 +0000
treeherdermozilla-inbound@428abebd41a3 [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)
 {