summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2025-06-26 11:33:58 +1000
committerMaxime Coste <mawww@kakoune.org>2025-06-26 11:33:58 +1000
commit096d72bbb11e3a2ec227de9eda4dfac02ed970aa (patch)
tree3ede8ff9628aa050c08c8eecbaf8b41a0e3b2d5f /src
parentf0f9d33243224d094e95750b860a636f9e3b0a99 (diff)
Delay destruction of item in hash map without returning an optional
Returning an optional of the removed item is not very idiomatic and we currently have no use case for this.
Diffstat (limited to 'src')
-rw-r--r--src/hash_map.hh21
1 files changed, 7 insertions, 14 deletions
diff --git a/src/hash_map.hh b/src/hash_map.hh
index dc6263e5..60ebc6ab 100644
--- a/src/hash_map.hh
+++ b/src/hash_map.hh
@@ -3,7 +3,6 @@
#include "hash.hh"
#include "memory.hh"
-#include "optional.hh"
#include "vector.hh"
namespace Kakoune
@@ -269,56 +268,50 @@ struct HashMap
}
template<typename KeyType> requires IsHashCompatible<Key, KeyType>
- constexpr Optional<Item> remove(const KeyType& key)
+ constexpr void remove(const KeyType& key)
{
- Optional<Item> removed;
const auto hash = hash_value(key);
int index = find_index(key, hash);
if (index >= 0)
{
- removed.emplace(std::move(m_items[index]));
+ [[maybe_unused]] Item keepalive = std::move(m_items[index]);
m_items.erase(m_items.begin() + index);
m_index.remove(hash, index);
m_index.ordered_fix_entries(index);
}
- return removed;
}
template<typename KeyType> requires IsHashCompatible<Key, KeyType>
- constexpr Optional<Item> unordered_remove(const KeyType& key)
+ constexpr void unordered_remove(const KeyType& key)
{
- Optional<Item> removed;
const auto hash = hash_value(key);
int index = find_index(key, hash);
if (index >= 0)
{
- removed.emplace(std::move(m_items[index]));
+ [[maybe_unused]] Item keepalive = std::move(m_items[index]);
m_items[index] = std::move(m_items.back());
m_items.pop_back();
m_index.remove(hash, index);
if (index != m_items.size())
m_index.unordered_fix_entries(hash_value(item_key(m_items[index])), m_items.size(), index);
}
- return removed;
}
template<typename KeyType> requires IsHashCompatible<Key, KeyType>
- constexpr Optional<Item> erase(const KeyType& key) { return unordered_remove(key); }
+ constexpr void erase(const KeyType& key) { return unordered_remove(key); }
template<typename KeyType> requires IsHashCompatible<Key, KeyType>
- constexpr Vector<Item> remove_all(const KeyType& key)
+ constexpr void remove_all(const KeyType& key)
{
- Vector<Item> removed;
const auto hash = hash_value(key);
for (int index = find_index(key, hash); index >= 0;
index = find_index(key, hash))
{
- removed.push_back(std::move(m_items[index]));
+ [[maybe_unused]] Item keepalive = std::move(m_items[index]);
m_items.erase(m_items.begin() + index);
m_index.remove(hash, index);
m_index.ordered_fix_entries(index);
}
- return removed;
}
using iterator = typename ContainerType::iterator;