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
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))
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))