[libcxx-commits] [libcxx] [libc++] Optimize hash table lookup (PR #230430)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Oct 9 02:53:06 PDT 2026
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/230430
None
>From fa62264cc6af739da7acc0af87510d5161a2487b Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Fri, 9 Oct 2026 11:52:42 +0200
Subject: [PATCH] [libc++] Optimize hash table lookup
---
libcxx/include/__hash_table | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table
index a03aa03090424..6dbd75804f000 100644
--- a/libcxx/include/__hash_table
+++ b/libcxx/include/__hash_table
@@ -168,11 +168,9 @@ public:
_LIBCPP_HIDE_FROM_ABI ~__hash_node() {}
};
-inline _LIBCPP_HIDE_FROM_ABI bool __is_hash_power2(size_t __bc) { return __bc > 2 && !(__bc & (__bc - 1)); }
+inline _LIBCPP_HIDE_FROM_ABI bool __is_hash_power2(size_t) { return false; }
-inline _LIBCPP_HIDE_FROM_ABI size_t __constrain_hash(size_t __h, size_t __bc) {
- return !(__bc & (__bc - 1)) ? __h & (__bc - 1) : (__h < __bc ? __h : __h % __bc);
-}
+inline _LIBCPP_HIDE_FROM_ABI size_t __constrain_hash(size_t __h, size_t __bc) { return __h % __bc; }
inline _LIBCPP_HIDE_FROM_ABI size_t __next_hash_pow2(size_t __n) {
return __n < 2 ? __n : (size_t(1) << (numeric_limits<size_t>::digits - std::__countl_zero(__n - 1)));
More information about the libcxx-commits
mailing list