Remove handling for unused LRUHandle representation special case.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=170876103
This commit is contained in:
costan 2017-10-03 10:33:01 -07:00 committed by Victor Costan
parent 2372ac574f
commit 4447f9cace

View File

@ -53,13 +53,11 @@ struct LRUHandle {
char key_data[1]; // Beginning of key char key_data[1]; // Beginning of key
Slice key() const { Slice key() const {
// For cheaper lookups, we allow a temporary Handle object // next_ is only equal to this if the LRU handle is the list head of an
// to store a pointer to a key in "value". // empty list. List heads never have meaningful keys.
if (next == this) { assert(next != this);
return *(reinterpret_cast<Slice*>(value));
} else { return Slice(key_data, key_length);
return Slice(key_data, key_length);
}
} }
}; };
@ -288,11 +286,10 @@ Cache::Handle* LRUCache::Insert(
LRU_Append(&in_use_, e); LRU_Append(&in_use_, e);
usage_ += charge; usage_ += charge;
FinishErase(table_.Insert(e)); FinishErase(table_.Insert(e));
} else { } else { // don't cache. (capacity_==0 is supported and turns off caching.)
// don't cache. (It is valid to set capacity_==0 to turn off caching.) // next is read by key() in an assert, so it must be initialized
e->next = NULL; e->next = NULL;
} }
while (usage_ > capacity_ && lru_.next != &lru_) { while (usage_ > capacity_ && lru_.next != &lru_) {
LRUHandle* old = lru_.next; LRUHandle* old = lru_.next;
assert(old->refs == 1); assert(old->refs == 1);