LruMap(LruMap const &);
LruMap & operator = (LruMap const &);
- bool expired(Entry &e);
+ bool expired(const Entry &e) const;
void trim();
void touch(const MapIterator &i);
bool del(const MapIterator &i);
index.erase(i->second);
i->second = index.begin();
- Entry *e = *i->second;
-
- if (e && expired(*e)) {
- del(i);
- e = NULL;
+ if (const Entry *e = *i->second) {
+ if (!expired(*e))
+ return;
+ // else fall through to cleanup
}
+
+ del(i);
+ i = storage.end();
}
template <class EntryValue, size_t EntryCost>
{
MapIterator i;
findEntry(key, i);
- Entry *e = *i->second;
if (i != storage.end()) {
touch(i);
+ Entry *e = *i->second;
return e->value;
}
return NULL;
template <class EntryValue, size_t EntryCost>
bool
-LruMap<EntryValue, EntryCost>::expired(LruMap::Entry &entry)
+LruMap<EntryValue, EntryCost>::expired(const LruMap::Entry &entry) const
{
if (ttl < 0)
return false;
LruMap<EntryValue, EntryCost>::del(LruMap::MapIterator const &i)
{
if (i != storage.end()) {
- delete *(i->second);
+ LruMap::Entry *e = *i->second;
index.erase(i->second);
storage.erase(i);
+ delete e;
--entries_;
return true;
}