mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-24 14:12:18 +00:00
DeltaFIFO cleanup
Remove non-needed else condition Remove non-needed swallow copy Simplify return for IsClosed() Keep amount decrement next to element extraction from the queue Signed-off-by: Adrián Orive <adrian.orive.oneca@gmail.com> Kubernetes-commit: 0b16c43f59b736060bc18e2e1de0e7fcc268f39b
This commit is contained in:
parent
e9ae4fad33
commit
cb4ba7f9b2
20
tools/cache/delta_fifo.go
vendored
20
tools/cache/delta_fifo.go
vendored
@ -320,17 +320,15 @@ func (f *DeltaFIFO) queueActionLocked(actionType DeltaType, obj interface{}) err
|
|||||||
newDeltas := append(f.items[id], Delta{actionType, obj})
|
newDeltas := append(f.items[id], Delta{actionType, obj})
|
||||||
newDeltas = dedupDeltas(newDeltas)
|
newDeltas = dedupDeltas(newDeltas)
|
||||||
|
|
||||||
_, exists := f.items[id]
|
|
||||||
if len(newDeltas) > 0 {
|
if len(newDeltas) > 0 {
|
||||||
if !exists {
|
if _, exists := f.items[id]; !exists {
|
||||||
f.queue = append(f.queue, id)
|
f.queue = append(f.queue, id)
|
||||||
}
|
}
|
||||||
f.items[id] = newDeltas
|
f.items[id] = newDeltas
|
||||||
f.cond.Broadcast()
|
f.cond.Broadcast()
|
||||||
} else if exists {
|
} else {
|
||||||
// We need to remove this from our map (extra items
|
// We need to remove this from our map (extra items in the queue are
|
||||||
// in the queue are ignored if they are not in the
|
// ignored if they are not in the map).
|
||||||
// map).
|
|
||||||
delete(f.items, id)
|
delete(f.items, id)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -348,9 +346,6 @@ func (f *DeltaFIFO) List() []interface{} {
|
|||||||
func (f *DeltaFIFO) listLocked() []interface{} {
|
func (f *DeltaFIFO) listLocked() []interface{} {
|
||||||
list := make([]interface{}, 0, len(f.items))
|
list := make([]interface{}, 0, len(f.items))
|
||||||
for _, item := range f.items {
|
for _, item := range f.items {
|
||||||
// Copy item's slice so operations on this slice
|
|
||||||
// won't interfere with the object we return.
|
|
||||||
item = copyDeltas(item)
|
|
||||||
list = append(list, item.Newest().Object)
|
list = append(list, item.Newest().Object)
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
@ -398,10 +393,7 @@ func (f *DeltaFIFO) GetByKey(key string) (item interface{}, exists bool, err err
|
|||||||
func (f *DeltaFIFO) IsClosed() bool {
|
func (f *DeltaFIFO) IsClosed() bool {
|
||||||
f.closedLock.Lock()
|
f.closedLock.Lock()
|
||||||
defer f.closedLock.Unlock()
|
defer f.closedLock.Unlock()
|
||||||
if f.closed {
|
return f.closed
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pop blocks until an item is added to the queue, and then returns it. If
|
// Pop blocks until an item is added to the queue, and then returns it. If
|
||||||
@ -432,10 +424,10 @@ func (f *DeltaFIFO) Pop(process PopProcessFunc) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
id := f.queue[0]
|
id := f.queue[0]
|
||||||
f.queue = f.queue[1:]
|
f.queue = f.queue[1:]
|
||||||
item, ok := f.items[id]
|
|
||||||
if f.initialPopulationCount > 0 {
|
if f.initialPopulationCount > 0 {
|
||||||
f.initialPopulationCount--
|
f.initialPopulationCount--
|
||||||
}
|
}
|
||||||
|
item, ok := f.items[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
// Item may have been deleted subsequently.
|
// Item may have been deleted subsequently.
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user