diff options
author | Eric Fiselier <eric@efcs.ca> | 2016-07-11 22:02:02 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2016-07-11 22:02:02 +0000 |
commit | 118cb4180f30a5e501a055dc859b326049a24be2 (patch) | |
tree | 3f0dcf7c3e98d21e4737f7e6b056940f8be93cab /libcxx | |
parent | c06bfa1daa96f59a072ab57ac3ab80bd39280b74 (diff) | |
download | llvm-118cb4180f30a5e501a055dc859b326049a24be2.zip llvm-118cb4180f30a5e501a055dc859b326049a24be2.tar.gz llvm-118cb4180f30a5e501a055dc859b326049a24be2.tar.bz2 |
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.
llvm-svn: 275114
Diffstat (limited to 'libcxx')
-rw-r--r-- | libcxx/include/__hash_table | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table index 8b25659..84ff167 100644 --- a/libcxx/include/__hash_table +++ b/libcxx/include/__hash_table @@ -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>::find(const _Key& __k) 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>::find(const _Key& __k) const 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)) |