trie/utils: address comment from martin

This commit is contained in:
Gary Rong 2023-11-13 18:44:44 +08:00
parent 8754ebc168
commit 1379079d5b

View file

@ -84,28 +84,20 @@ func NewPointCache(maxItems int) *PointCache {
} }
} }
// get loads the cached commitment, or nil if it's not existent.
func (c *PointCache) get(addr string) (*verkle.Point, bool) {
c.lock.RLock()
defer c.lock.RUnlock()
return c.lru.Get(addr)
}
// Get returns the cached commitment for the specified address, or computing // Get returns the cached commitment for the specified address, or computing
// it on the flight. // it on the flight.
func (c *PointCache) Get(addr []byte) *verkle.Point { func (c *PointCache) Get(addr []byte) *verkle.Point {
p, ok := c.get(string(addr)) c.lock.Lock()
defer c.lock.Unlock()
p, ok := c.lru.Get(string(addr))
if ok { if ok {
cacheHitGauge.Inc(1) cacheHitGauge.Inc(1)
return p return p
} }
cacheMissGauge.Inc(1) cacheMissGauge.Inc(1)
p = evaluateAddressPoint(addr) p = evaluateAddressPoint(addr)
c.lock.Lock()
c.lru.Add(string(addr), p) c.lru.Add(string(addr), p)
c.lock.Unlock()
return p return p
} }