mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +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>
|
template<typename Value2>
|
||||||
void _emplace(const Key& key, Value2&& v)
|
void _emplace(const Key& key, Value2&& v)
|
||||||
{
|
{
|
||||||
truncate_if_needed();
|
|
||||||
auto it = cacheMap.find(key);
|
auto it = cacheMap.find(key);
|
||||||
if (it == cacheMap.end()) {
|
if (it == cacheMap.end()) {
|
||||||
cacheMap.emplace(key, std::make_pair(std::forward<Value2>(v), accessCounter++));
|
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.first = std::forward<Value2>(v);
|
||||||
it->second.second = accessCounter++;
|
it->second.second = accessCounter++;
|
||||||
}
|
}
|
||||||
|
truncate_if_needed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void emplace(const Key& key, Value&& v)
|
void emplace(const Key& key, Value&& v)
|
||||||
|
Loading…
Reference in New Issue
Block a user