Annotate out-of-line large string hash functions as pure. `CombineLargeContiguousImplOn32BitLengthGt8` and `CombineLargeContiguousImplOn64BitLengthGt32` only read `len` bytes starting at `first` and return a 64-bit hash state without modifying any memory or observable program state. However, because `first` is passed into an out-of-line call, the compiler must conservatively assume that the call could alias and clobber heap or stack memory reachable from `first`—including the `std::string` key or SwissTable header fields when a short-string buffer address is passed. Mark both declarations with `ABSL_ATTRIBUTE_PURE_FUNCTION` (`__attribute__((pure))`) so the optimizer knows the out-of-line large buffer hash does not mutate memory. When hashing a contiguous key (`std::string`, `absl::string_view`, `std::vector`, `absl::Span`, etc.) in a SwissTable lookup, the compiler can keep the table's `common()` fields and the key's data pointer and length live across the cold `len > 32` call rather than reloading them from memory before the probe loop. PiperOrigin-RevId: 989331761
diff --git a/absl/hash/internal/hash.h b/absl/hash/internal/hash.h index 025e57c..c0d3833 100644 --- a/absl/hash/internal/hash.h +++ b/absl/hash/internal/hash.h
@@ -1164,12 +1164,14 @@ // 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. -uint64_t CombineLargeContiguousImplOn32BitLengthGt8(uint64_t state, - const unsigned char* first, - size_t len); -uint64_t CombineLargeContiguousImplOn64BitLengthGt32(uint64_t state, - const unsigned char* first, - size_t len); +ABSL_ATTRIBUTE_PURE_FUNCTION uint64_t +CombineLargeContiguousImplOn32BitLengthGt8(uint64_t state, + const unsigned char* first, + size_t len); +ABSL_ATTRIBUTE_PURE_FUNCTION uint64_t +CombineLargeContiguousImplOn64BitLengthGt32(uint64_t state, + const unsigned char* first, + size_t len); ABSL_ATTRIBUTE_ALWAYS_INLINE inline uint64_t CombineSmallContiguousImpl( uint64_t state, const unsigned char* first, size_t len) {