Skip to content

Commit

Permalink
drop averageDecorators slice from bState struct
Browse files Browse the repository at this point in the history
DecoratorAverageAdjust is very uncommon method to call because start
time can be set at construction time. It's not worth to keep slice for
method which is potentially never called.
  • Loading branch information
vbauerster committed Aug 17, 2024
1 parent 43976da commit 423ec45
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions bar.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type bState struct {
autoRefresh bool
buffers [3]*bytes.Buffer
decorators [2][]decor.Decorator
averageDecorators []decor.AverageDecorator
ewmaDecorators []decor.EwmaDecorator
shutdownListeners []decor.ShutdownListener
filler BarFiller
Expand Down Expand Up @@ -319,18 +318,16 @@ func (b *Bar) EwmaIncrInt64(n int64, iterDur time.Duration) {
}
}

// DecoratorAverageAdjust adjusts all average based decorators. Call
// if you need to adjust start time of all average based decorators
// or after progress resume.
// DecoratorAverageAdjust adjusts all average based decorators.
// Call if you need to set start time after decorators have been constructed.
// For this method to work average decorators must implement
// decor.AverageDecorator interface.
func (b *Bar) DecoratorAverageAdjust(start time.Time) {
select {
case b.operateState <- func(s *bState) {
for _, d := range s.averageDecorators {
b.TraverseDecorators(func(d decor.Decorator) {
if d, ok := d.(decor.AverageDecorator); ok {
d.AverageAdjust(start)
}
}:
case <-b.ctx.Done():
}
})
}

// SetPriority changes bar's order among multiple bars. Zero is highest
Expand Down Expand Up @@ -552,9 +549,6 @@ func (s *bState) wSyncTable() (table syncTable) {
func (s *bState) sortDecorators(decorators []decor.Decorator) {
for _, d := range decorators {
d := unwrap(d)
if d, ok := d.(decor.AverageDecorator); ok {
s.averageDecorators = append(s.averageDecorators, d)
}
if d, ok := d.(decor.EwmaDecorator); ok {
s.ewmaDecorators = append(s.ewmaDecorators, d)
}
Expand Down

0 comments on commit 423ec45

Please sign in to comment.