aboutsummaryrefslogtreecommitdiff
path: root/libcxx
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-07-17 22:04:57 +0000
committerEric Fiselier <eric@efcs.ca>2016-07-17 22:04:57 +0000
commit6a411472e3c4d707a3e25058f9ffadb25691a7f5 (patch)
tree0d9076f16575daeac4d722f26e232d26cfc4458a /libcxx
parent5fe4d141e07c1c868c1a11a2b52cfb1ad829c086 (diff)
downloadllvm-6a411472e3c4d707a3e25058f9ffadb25691a7f5.zip
llvm-6a411472e3c4d707a3e25058f9ffadb25691a7f5.tar.gz
llvm-6a411472e3c4d707a3e25058f9ffadb25691a7f5.tar.bz2
Check for unconstrained hash equality before constrained hash equality.
This patch implements a simple optimization in __hash_table::find. When iterating the found bucket we only constrain the bucket elements hash if it doesn't already match the unconstrained hash of the specified key. This prevent the performance of an expensive modulo operation. Since the bucket element almost always matches the key, especially when the load factor is low, this optimization has large performance impacts. For a unordered_set<int> of random integers this patch improves the performance of 'find(...)' by 40%. llvm-svn: 275734
Diffstat (limited to 'libcxx')
-rw-r--r--libcxx/include/__hash_table5
1 files changed, 3 insertions, 2 deletions
diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table
index 84ff167..08bc519 100644
--- a/libcxx/include/__hash_table
+++ b/libcxx/include/__hash_table
@@ -2202,7 +2202,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k)
if (__nd != nullptr)
{
for (__nd = __nd->__next_; __nd != nullptr &&
- __constrain_hash(__nd->__hash_, __bc) == __chash;
+ (__nd->__hash_ == __hash
+ || __constrain_hash(__nd->__hash_, __bc) == __chash);
__nd = __nd->__next_)
{
if ((__nd->__hash_ == __hash) && key_eq()(__nd->__value_, __k))
@@ -2231,7 +2232,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const
if (__nd != nullptr)
{
for (__nd = __nd->__next_; __nd != nullptr &&
- __constrain_hash(__nd->__hash_, __bc) == __chash;
+ (__hash == __nd->__hash_ || __constrain_hash(__nd->__hash_, __bc) == __chash);
__nd = __nd->__next_)
{
if ((__nd->__hash_ == __hash) && key_eq()(__nd->__value_, __k))