diff options
| author | Maxime Coste <mawww@kakoune.org> | 2023-11-17 17:01:51 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2023-11-17 17:01:51 +1100 |
| commit | 296ab1a1ffb707f4691cdce21172b3b8d0b48eb0 (patch) | |
| tree | 6388c07b53a5cfda953b92c058a819684bcec67f /src/hash_map.hh | |
| parent | b10a935b8ceb18f256bd04843a5442d7c746abdb (diff) | |
Improve WordDB performance by precomputing hashes
Avoid multiple computation of string hashes by making it possible
to pre-compute and pass hashes to interned strings and hash maps.
Diffstat (limited to 'src/hash_map.hh')
| -rw-r--r-- | src/hash_map.hh | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/hash_map.hh b/src/hash_map.hh index f5bc9412..2f2f6042 100644 --- a/src/hash_map.hh +++ b/src/hash_map.hh @@ -194,9 +194,9 @@ struct HashMap insert(*begin++); } - constexpr EffectiveValue& insert(Item item) + constexpr EffectiveValue& insert(Item item, size_t hash) { - const auto hash = hash_value(item_key(item)); + kak_assert(hash == hash_value(item_key(item))); if constexpr (not multi_key) { if (auto index = find_index(item_key(item), hash); index >= 0) @@ -212,6 +212,11 @@ struct HashMap return item_value(m_items.back()); } + constexpr EffectiveValue& insert(Item item) + { + return insert(std::move(item), hash_value(item_key(item))); + } + template<typename KeyType> requires IsHashCompatible<Key, KeyType> constexpr int find_index(const KeyType& key, size_t hash) const { @@ -313,6 +318,7 @@ struct HashMap constexpr const_iterator begin() const { return m_items.begin(); } constexpr const_iterator end() const { return m_items.end(); } + Item& item(size_t index) { return m_items[index]; } const Item& item(size_t index) const { return m_items[index]; } template<typename KeyType> requires IsHashCompatible<Key, KeyType> |
