Codebase list golang-github-vbauerster-mpb / 9281696
sort decorators at ranging over bar options Vladimir Bauer 1 year, 10 months ago
3 changed file(s) with 13 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
551551 return table
552552 }
553553
554 func (s *bState) sortDecorators() {
555 for _, decorators := range s.decorators {
556 for _, d := range decorators {
557 d := unwrap(d)
558 if d, ok := d.(decor.AverageDecorator); ok {
559 s.averageDecorators = append(s.averageDecorators, d)
560 }
561 if d, ok := d.(decor.EwmaDecorator); ok {
562 s.ewmaDecorators = append(s.ewmaDecorators, d)
563 }
564 if d, ok := d.(decor.ShutdownListener); ok {
565 s.shutdownListeners = append(s.shutdownListeners, d)
566 }
554 func (s *bState) sortDecorators(decorators []decor.Decorator) {
555 for _, d := range decorators {
556 d := unwrap(d)
557 if d, ok := d.(decor.AverageDecorator); ok {
558 s.averageDecorators = append(s.averageDecorators, d)
559 }
560 if d, ok := d.(decor.EwmaDecorator); ok {
561 s.ewmaDecorators = append(s.ewmaDecorators, d)
562 }
563 if d, ok := d.(decor.ShutdownListener); ok {
564 s.shutdownListeners = append(s.shutdownListeners, d)
567565 }
568566 }
569567 }
2323 func PrependDecorators(decorators ...decor.Decorator) BarOption {
2424 decorators = inspect(decorators)
2525 return func(s *bState) {
26 s.sortDecorators(decorators)
2627 s.decorators[0] = decorators
2728 }
2829 }
3132 func AppendDecorators(decorators ...decor.Decorator) BarOption {
3233 decorators = inspect(decorators)
3334 return func(s *bState) {
35 s.sortDecorators(decorators)
3436 s.decorators[1] = decorators
3537 }
3638 }
450450 bs.buffers[1] = bytes.NewBuffer(make([]byte, 0, 128)) // append
451451 bs.buffers[2] = bytes.NewBuffer(make([]byte, 0, 256)) // filler
452452
453 bs.sortDecorators()
454
455453 return bs
456454 }