mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 22:26:42 +00:00
common/lru: shorten return names
This commit is contained in:
parent
1c64c74f07
commit
b04157fafe
1 changed files with 7 additions and 7 deletions
|
|
@ -52,32 +52,32 @@ func (c *BasicLRU[K, V]) Add(key K, value V) (evicted bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add3 adds a value to the cache. If an item was evicted to store the new one, it returns the evicted item.
|
// Add3 adds a value to the cache. If an item was evicted to store the new one, it returns the evicted item.
|
||||||
func (c *BasicLRU[K, V]) Add3(key K, value V) (evKey K, evItem V, evicted bool) {
|
func (c *BasicLRU[K, V]) Add3(key K, value V) (ek K, ev V, evicted bool) {
|
||||||
item, ok := c.items[key]
|
item, ok := c.items[key]
|
||||||
if ok {
|
if ok {
|
||||||
item.value = value
|
item.value = value
|
||||||
c.items[key] = item
|
c.items[key] = item
|
||||||
c.list.moveToFront(item.elem)
|
c.list.moveToFront(item.elem)
|
||||||
return evKey, evItem, false
|
return ek, ev, false
|
||||||
}
|
}
|
||||||
|
|
||||||
var elem *listElem[K]
|
var elem *listElem[K]
|
||||||
if c.Len() >= c.cap {
|
if c.Len() >= c.cap {
|
||||||
elem = c.list.removeLast()
|
elem = c.list.removeLast()
|
||||||
evicted = true
|
evicted = true
|
||||||
evKey = elem.v
|
ek = elem.v
|
||||||
evItem = c.items[evKey].value
|
ev = c.items[ek].value
|
||||||
delete(c.items, evKey)
|
delete(c.items, ek)
|
||||||
} else {
|
} else {
|
||||||
elem = new(listElem[K])
|
elem = new(listElem[K])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the new item.
|
// Store the new item.
|
||||||
// Note that, if another item was evicted, we re-use its list element here.
|
// Note that if another item was evicted, we re-use its list element here.
|
||||||
elem.v = key
|
elem.v = key
|
||||||
c.items[key] = cacheItem[K, V]{elem, value}
|
c.items[key] = cacheItem[K, V]{elem, value}
|
||||||
c.list.pushElem(elem)
|
c.list.pushElem(elem)
|
||||||
return evKey, evItem, evicted
|
return ek, ev, evicted
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contains reports whether the given key exists in the cache.
|
// Contains reports whether the given key exists in the cache.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue