summaryrefslogtreecommitdiff
path: root/util/cache.cc
diff options
context:
space:
mode:
authorcostan <costan@google.com>2017-10-03 10:33:01 -0700
committerVictor Costan <pwnall@chromium.org>2017-10-03 11:32:02 -0700
commit4447f9caced2bd09585c90f1b203c3aa8f4bbc40 (patch)
treeabaf49db02ddaf667f7c27f2d503b5566b9f3d9e /util/cache.cc
parent2372ac574fdeb1235e70cdd86a2681d1ce05cf65 (diff)
downloadleveldb-4447f9caced2bd09585c90f1b203c3aa8f4bbc40.tar.gz
Remove handling for unused LRUHandle representation special case.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=170876103
Diffstat (limited to 'util/cache.cc')
-rw-r--r--util/cache.cc17
1 files changed, 7 insertions, 10 deletions
diff --git a/util/cache.cc b/util/cache.cc
index 97b82ea..bd914ae 100644
--- a/util/cache.cc
+++ b/util/cache.cc
@@ -53,13 +53,11 @@ struct LRUHandle {
char key_data[1]; // Beginning of key
Slice key() const {
- // For cheaper lookups, we allow a temporary Handle object
- // to store a pointer to a key in "value".
- if (next == this) {
- return *(reinterpret_cast<Slice*>(value));
- } else {
- return Slice(key_data, key_length);
- }
+ // next_ is only equal to this if the LRU handle is the list head of an
+ // empty list. List heads never have meaningful keys.
+ assert(next != this);
+
+ return Slice(key_data, key_length);
}
};
@@ -288,11 +286,10 @@ Cache::Handle* LRUCache::Insert(
LRU_Append(&in_use_, e);
usage_ += charge;
FinishErase(table_.Insert(e));
- } else {
- // don't cache. (It is valid to set capacity_==0 to turn off caching.)
+ } else { // don't cache. (capacity_==0 is supported and turns off caching.)
+ // next is read by key() in an assert, so it must be initialized
e->next = NULL;
}
-
while (usage_ > capacity_ && lru_.next != &lru_) {
LRUHandle* old = lru_.next;
assert(old->refs == 1);