[libcxx] r275114 - Don't compute modulus of hash if it is smaller than the bucket count.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 11 15:02:02 PDT 2016
Author: ericwf
Date: Mon Jul 11 17:02:02 2016
New Revision: 275114
URL: http://llvm.org/viewvc/llvm-project?rev=275114&view=rev
Log:
Don't compute modulus of hash if it is smaller than the bucket count.
This cleans up a previous optimization attempt in hash, and results in
additional performance improvements over that previous attempt. Additionally
this new optimization does not hinder the power of 2 bucket count optimization.
Modified:
libcxx/trunk/include/__hash_table
Modified: libcxx/trunk/include/__hash_table
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__hash_table?rev=275114&r1=275113&r2=275114&view=diff
==============================================================================
--- libcxx/trunk/include/__hash_table (original)
+++ libcxx/trunk/include/__hash_table Mon Jul 11 17:02:02 2016
@@ -90,7 +90,8 @@ inline _LIBCPP_INLINE_VISIBILITY
size_t
__constrain_hash(size_t __h, size_t __bc)
{
- return !(__bc & (__bc - 1)) ? __h & (__bc - 1) : __h % __bc;
+ return !(__bc & (__bc - 1)) ? __h & (__bc - 1) :
+ (__h < __bc ? __h : __h % __bc);
}
inline _LIBCPP_INLINE_VISIBILITY
@@ -2201,8 +2202,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>
if (__nd != nullptr)
{
for (__nd = __nd->__next_; __nd != nullptr &&
- (__hash == __nd->__hash_
- || __constrain_hash(__nd->__hash_, __bc) == __chash);
+ __constrain_hash(__nd->__hash_, __bc) == __chash;
__nd = __nd->__next_)
{
if ((__nd->__hash_ == __hash) && key_eq()(__nd->__value_, __k))
@@ -2231,8 +2231,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>
if (__nd != nullptr)
{
for (__nd = __nd->__next_; __nd != nullptr &&
- (__hash == __nd->__hash_
- || __constrain_hash(__nd->__hash_, __bc) == __chash);
+ __constrain_hash(__nd->__hash_, __bc) == __chash;
__nd = __nd->__next_)
{
if ((__nd->__hash_ == __hash) && key_eq()(__nd->__value_, __k))
More information about the cfe-commits
mailing list