Skip to content

Commit d52af02

Browse files
committed
code optimization
1 parent 3926bca commit d52af02

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

core/hotspot/cache/lru.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,20 @@ func (c *LRU) Contains(key interface{}) (ok bool) {
129129
func (c *LRU) Peek(key interface{}) (value interface{}, isFound bool) {
130130
var ent *list.Element
131131
if ent, isFound = c.items[key]; isFound {
132-
return ent.Value.(*entry).value, true
132+
return ent.Value.(*entry).value, isFound
133133
}
134134
return nil, isFound
135135
}
136136

137137
// Remove removes the provided key from the cache, returning if the
138138
// key was contained.
139139
func (c *LRU) Remove(key interface{}) (isFound bool) {
140-
if ent, ok := c.items[key]; ok {
140+
var ent *list.Element
141+
if ent, isFound = c.items[key]; isFound {
141142
c.removeElement(ent)
142-
return true
143+
return
143144
}
144-
return false
145+
return
145146
}
146147

147148
// RemoveOldest removes the oldest item from the cache.

core/hotspot/traffic_shaping.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ func (c *baseTrafficShapingController) BoundMetric() *ParamsMetric {
115115

116116
func (c *baseTrafficShapingController) performCheckingForConcurrencyMetric(arg interface{}) *base.TokenResult {
117117
specificItem := c.specificItems
118-
initConcurrency := new(int64)
119-
*initConcurrency = 0
120-
concurrencyPtr := c.metric.ConcurrencyCounter.AddIfAbsent(arg, initConcurrency)
118+
initConcurrency := int64(0)
119+
concurrencyPtr := c.metric.ConcurrencyCounter.AddIfAbsent(arg, &initConcurrency)
121120
if concurrencyPtr == nil {
122121
// First to access this arg
123122
return nil

0 commit comments

Comments
 (0)