Type erase AssertHashEqConsistent to improve compilation time for debug builds.

PiperOrigin-RevId: 991099048
Change-Id: Ic235b8fdf8d2f1000efcc3c503b6595007b961d7
diff --git a/absl/container/internal/raw_hash_set.cc b/absl/container/internal/raw_hash_set.cc
index 00e154e..0a72ee3 100644
--- a/absl/container/internal/raw_hash_set.cc
+++ b/absl/container/internal/raw_hash_set.cc
@@ -984,38 +984,6 @@
   Destruct<kSooEnabled>(c, policy, kStandardDeallocBackingArrayFn);
 }
 
-void AssertHashEqConsistentImpl(CommonFields& common,
-                            const PolicyFunctions& __restrict policy,
-                            size_t hash,
-                            absl::FunctionRef<bool(void* slot)> equal) {
-  if (common.empty()) return;
-
-  const void* hash_fn = policy.hash_fn(common);
-  const size_t seed = common.seed().seed();
-
-  const auto assert_consistent = [&](const ctrl_t*, void* slot) {
-    const bool is_key_equal = equal(slot);
-    if (!is_key_equal) return;
-
-    [[maybe_unused]] const bool is_hash_equal =
-        hash == policy.hash_slot(hash_fn, slot, seed);
-    assert((!is_key_equal || is_hash_equal) &&
-           "eq(k1, k2) must imply that hash(k1) == hash(k2). "
-           "hash/eq functors are inconsistent.");
-  };
-
-  if (common.is_small()) {
-    assert_consistent(
-        /*unused*/ nullptr,
-        policy.soo_enabled ? SingleSlotAddress</*kSooEnabled=*/true>(common)
-                           : SingleSlotAddress</*kSooEnabled=*/false>(common));
-    return;
-  }
-  // We only do validation for small tables so that it's constant time.
-  if (common.capacity() > 16) return;
-  IterateOverFullSlots(common, policy.slot_size, assert_consistent);
-}
-
 namespace {
 
 // Iterates over full slots in old table, finds new positions for them and
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h
index 0ae7956..1ae02b3 100644
--- a/absl/container/internal/raw_hash_set.h
+++ b/absl/container/internal/raw_hash_set.h
@@ -2177,12 +2177,6 @@
 template <bool kSooEnabled>
 void Destruct(CommonFields& c, const DtorPolicy& policy);
 
-// Asserts that hash and equal functors provided by the user are consistent,
-// meaning that `eq(k1, k2)` implies `hash(k1)==hash(k2)`.
-void AssertHashEqConsistentImpl(CommonFields& common,
-                                const PolicyFunctions& policy, size_t hash,
-                                absl::FunctionRef<bool(void* slot)> equal);
-
 // Type-erased versions of raw_hash_set::erase_meta_only_{small,large}.
 void EraseMetaOnlySmall(CommonFields& c, bool soo_enabled, size_t slot_size);
 void EraseMetaOnlyLarge(CommonFields& c, size_t index, size_t slot_size);
@@ -3819,9 +3813,27 @@
         std::is_same_v<hasher, absl::Hash<key_type>> &&
         std::is_same_v<key_equal, std::equal_to<key_type>>;
     if constexpr (kIsDebug && !kIsStringAbslHashEq && !kIsScalarAbslHashEq) {
-      AssertHashEqConsistentImpl(
-          common(), GetPolicyFunctions(), hash_of(key),
-          [&](void* slot) { return equal_to(key, to_slot(slot)); });
+      if (empty()) return;
+
+      const size_t hash_of_arg = hash_of(key);
+      const auto assert_consistent = [&](const ctrl_t*, void* slot) {
+        const bool is_key_equal = equal_to(key, to_slot(slot));
+        if (!is_key_equal) return;
+
+        [[maybe_unused]] const bool is_hash_equal =
+            hash_of_arg == hash_of(to_slot(slot));
+        assert((!is_key_equal || is_hash_equal) &&
+               "eq(k1, k2) must imply that hash(k1) == hash(k2). "
+               "hash/eq functors are inconsistent.");
+      };
+
+      if (is_small()) {
+        assert_consistent(/*unused*/ nullptr, single_slot());
+        return;
+      }
+      // We only do validation for small tables so that it's constant time.
+      if (capacity() > 16) return;
+      IterateOverFullSlots(common(), sizeof(slot_type), assert_consistent);
     }
   }