Refactor: define CombineRawImpl for repeated `Mix(state ^ value, kMul)` operations. PiperOrigin-RevId: 777635780 Change-Id: I7b7305fd27ae552f8b96cc93adb3593385381089
diff --git a/absl/hash/internal/hash.cc b/absl/hash/internal/hash.cc index 8dcc5bd..a693d5c 100644 --- a/absl/hash/internal/hash.cc +++ b/absl/hash/internal/hash.cc
@@ -101,9 +101,9 @@ const unsigned char* data, size_t len, uint64_t state) { // TODO(b/417141985): expose and use CityHash32WithSeed. // Note: we can't use PrecombineLengthMix here because len can be up to 1024. - return Mix((state + len) ^ hash_internal::CityHash32( - reinterpret_cast<const char*>(data), len), - kMul); + return CombineRawImpl( + state + len, + hash_internal::CityHash32(reinterpret_cast<const char*>(data), len)); } ABSL_ATTRIBUTE_NOINLINE uint64_t
diff --git a/absl/hash/internal/hash.h b/absl/hash/internal/hash.h index 8fd9e97..21728b0 100644 --- a/absl/hash/internal/hash.h +++ b/absl/hash/internal/hash.h
@@ -1034,6 +1034,11 @@ return mem0 | mem1; } +ABSL_ATTRIBUTE_ALWAYS_INLINE inline uint64_t CombineRawImpl(uint64_t state, + uint64_t value) { + return Mix(state ^ value, kMul); +} + // Slow dispatch path for calls to CombineContiguousImpl with a size argument // larger than inlined size. Has the same effect as calling // CombineContiguousImpl() repeatedly with the chunk stride size. @@ -1055,7 +1060,7 @@ // Empty string must modify the state. v = 0x57; } - return Mix(state ^ v, kMul); + return CombineRawImpl(state, v); } ABSL_ATTRIBUTE_ALWAYS_INLINE inline uint64_t CombineContiguousImpl9to16( @@ -1263,7 +1268,7 @@ template <typename T, absl::enable_if_t<IntegralFastPath<T>::value, int> = 0> static size_t hash_with_seed(T value, size_t seed) { return static_cast<size_t>( - Mix(seed ^ static_cast<std::make_unsigned_t<T>>(value), kMul)); + CombineRawImpl(seed, static_cast<std::make_unsigned_t<T>>(value))); } template <typename T, absl::enable_if_t<!IntegralFastPath<T>::value, int> = 0> @@ -1301,7 +1306,7 @@ // optimize Read1To3 and Read4To8 differently for the string case. static MixingHashState combine_raw(MixingHashState hash_state, uint64_t value) { - return MixingHashState(Mix(hash_state.state_ ^ value, kMul)); + return MixingHashState(CombineRawImpl(hash_state.state_, value)); } static MixingHashState combine_weakly_mixed_integer(