[libcxx-commits] [libcxx] cc6b4f8 - [libc++] Optimize hash table lookup (#230430)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 14 00:25:47 PDT 2026


Author: Nikolas Klauser
Date: 2026-10-14T09:25:41+02:00
New Revision: cc6b4f8acbd6fbf5fa270df71de9d7ad6a7870ed

URL: https://github.com/llvm/llvm-project/commit/cc6b4f8acbd6fbf5fa270df71de9d7ad6a7870ed
DIFF: https://github.com/llvm/llvm-project/commit/cc6b4f8acbd6fbf5fa270df71de9d7ad6a7870ed.diff

LOG: [libc++] Optimize hash table lookup (#230430)

It seems that on modern hardware the extra branch for avoiding a
division isn't worth the avoided compute anymore.

Added: 
    

Modified: 
    libcxx/include/__hash_table

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table
index e157221e817af..23916e3a3ecf3 100644
--- a/libcxx/include/__hash_table
+++ b/libcxx/include/__hash_table
@@ -171,7 +171,7 @@ public:
 inline _LIBCPP_HIDE_FROM_ABI bool __is_hash_power2(size_t __bc) { return __bc > 2 && !(__bc & (__bc - 1)); }
 
 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);
+  return !(__bc & (__bc - 1)) ? __h & (__bc - 1) : __h % __bc;
 }
 
 inline _LIBCPP_HIDE_FROM_ABI size_t __next_hash_pow2(size_t __n) {


        


More information about the libcxx-commits mailing list