diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-01-20 14:49:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-20 14:49:05 +0100 |
commit | 12cc57d1ad0cf6dcf946884100c905a1768e302a (patch) | |
tree | 6654b03d9d5b028546485e56f42b14329b820062 | |
parent | 286b29be89ed6431acca9a74f057af0a412dbd3e (diff) | |
parent | e7fa653562ee513322db0f7dca50568c3934a680 (diff) |
Merge pull request #25655 from vespa-engine/balder/bring-force-insert-back-to-glory-2
Splitt force_insert into hot/cold parts.
-rw-r--r-- | vespalib/src/vespa/vespalib/stllike/hashtable.h | 1 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/stllike/hashtable.hpp | 32 |
2 files changed, 20 insertions, 13 deletions
diff --git a/vespalib/src/vespa/vespalib/stllike/hashtable.h b/vespalib/src/vespa/vespalib/stllike/hashtable.h index 8665b4d235e..553cda1e6c0 100644 --- a/vespalib/src/vespa/vespalib/stllike/hashtable.h +++ b/vespalib/src/vespa/vespalib/stllike/hashtable.h @@ -363,6 +363,7 @@ private: } template <typename MoveHandler> VESPA_DLL_LOCAL void reclaim(MoveHandler & moveHandler, next_t node); + VESPA_DLL_LOCAL void force_insert_cold(Value && value, next_t node) __attribute__((noinline)); }; } diff --git a/vespalib/src/vespa/vespalib/stllike/hashtable.hpp b/vespalib/src/vespa/vespalib/stllike/hashtable.hpp index f60e98c350e..1b12bfba427 100644 --- a/vespalib/src/vespa/vespalib/stllike/hashtable.hpp +++ b/vespalib/src/vespa/vespalib/stllike/hashtable.hpp @@ -185,23 +185,29 @@ hashtable<Key, Value, Hash, Equal, KeyExtract, Modulator>::insertInternal(V && n template <typename Key, typename Value, typename Hash, typename Equal, typename KeyExtract, typename Modulator> void -hashtable<Key, Value, Hash, Equal, KeyExtract, Modulator>::force_insert(Value && value) -{ +hashtable<Key, Value, Hash, Equal, KeyExtract, Modulator>::force_insert(Value && value) { const next_t h = hash(_keyExtractor(value)); - if ( ! _nodes[h].valid() ) [[likely]] { + if (!_nodes[h].valid()) [[likely]] { _nodes[h] = std::move(value); _count++; } else { - if (_nodes.size() < _nodes.capacity()) [[likely]] { - const next_t p(_nodes[h].getNext()); - const next_t newIdx(_nodes.size()); - _nodes[h].setNext(newIdx); - _nodes.template emplace_back(std::move(value), p); - _count++; - } else { - resize(_nodes.capacity()*2); - force_insert(std::move(value)); - } + force_insert_cold(std::move(value), h); + } +} + +template <typename Key, typename Value, typename Hash, typename Equal, typename KeyExtract, typename Modulator> +void +hashtable<Key, Value, Hash, Equal, KeyExtract, Modulator>::force_insert_cold(Value && value, next_t h) +{ + if (_nodes.size() < _nodes.capacity()) [[likely]] { + const next_t p(_nodes[h].getNext()); + const next_t newIdx(_nodes.size()); + _nodes[h].setNext(newIdx); + _nodes.template emplace_back(std::move(value), p); + _count++; + } else { + resize(_nodes.capacity()*2); + force_insert(std::move(value)); } } |