diff options
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/lru-cache.hh | 8 | ||||
-rw-r--r-- | src/libutil/sync.hh | 1 |
2 files changed, 6 insertions, 3 deletions
diff --git a/src/libutil/lru-cache.hh b/src/libutil/lru-cache.hh index 35983aa2c918..3cb5d50889d9 100644 --- a/src/libutil/lru-cache.hh +++ b/src/libutil/lru-cache.hh @@ -11,7 +11,7 @@ class LRUCache { private: - size_t maxSize; + size_t capacity; // Stupid wrapper to get around circular dependency between Data // and LRU. @@ -27,14 +27,16 @@ private: public: - LRUCache(size_t maxSize) : maxSize(maxSize) { } + LRUCache(size_t capacity) : capacity(capacity) { } /* Insert or upsert an item in the cache. */ void upsert(const Key & key, const Value & value) { + if (capacity == 0) return; + erase(key); - if (data.size() >= maxSize) { + if (data.size() >= capacity) { /* Retire the oldest item. */ auto oldest = lru.begin(); data.erase(*oldest); diff --git a/src/libutil/sync.hh b/src/libutil/sync.hh index 2aa074299b23..611c900e0a32 100644 --- a/src/libutil/sync.hh +++ b/src/libutil/sync.hh @@ -33,6 +33,7 @@ public: Sync() { } Sync(const T & data) : data(data) { } + Sync(T && data) noexcept : data(std::move(data)) { } class Lock { |