mirror of
https://github.com/ceph/ceph
synced 2025-02-22 18:47:18 +00:00
common/shared_cache.hpp: compact to a single lookup where possible
Signed-off-by: Samuel Just <sam.just@inktank.com>
This commit is contained in:
parent
27b5f2b873
commit
ee48c871d6
@ -44,16 +44,20 @@ class SharedLRU {
|
||||
}
|
||||
|
||||
void lru_remove(K key) {
|
||||
if (!contents.count(key))
|
||||
typename map<K, typename list<pair<K, VPtr> >::iterator>::iterator i =
|
||||
contents.find(key);
|
||||
if (i == contents.end())
|
||||
return;
|
||||
lru.erase(contents[key]);
|
||||
lru.erase(i->second);
|
||||
--size;
|
||||
contents.erase(key);
|
||||
contents.erase(i);
|
||||
}
|
||||
|
||||
void lru_add(K key, VPtr val, list<VPtr> *to_release) {
|
||||
if (contents.count(key)) {
|
||||
lru.splice(lru.begin(), lru, contents[key]);
|
||||
typename map<K, typename list<pair<K, VPtr> >::iterator>::iterator i =
|
||||
contents.find(key);
|
||||
if (i != contents.end()) {
|
||||
lru.splice(lru.begin(), lru, i->second);
|
||||
} else {
|
||||
++size;
|
||||
lru.push_front(make_pair(key, val));
|
||||
|
Loading…
Reference in New Issue
Block a user