mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
fix: off-by-1 in unordered_lru_cache
we should be truncating after (potentially) adding new element, not before we even tried to do so
This commit is contained in:
parent
62540743ef
commit
4921903663
@ -36,7 +36,6 @@ public:
|
||||
template<typename Value2>
|
||||
void _emplace(const Key& key, Value2&& v)
|
||||
{
|
||||
truncate_if_needed();
|
||||
auto it = cacheMap.find(key);
|
||||
if (it == cacheMap.end()) {
|
||||
cacheMap.emplace(key, std::make_pair(std::forward<Value2>(v), accessCounter++));
|
||||
@ -44,6 +43,7 @@ public:
|
||||
it->second.first = std::forward<Value2>(v);
|
||||
it->second.second = accessCounter++;
|
||||
}
|
||||
truncate_if_needed();
|
||||
}
|
||||
|
||||
void emplace(const Key& key, Value&& v)
|
||||
|
Loading…
Reference in New Issue
Block a user