sort decorators at ranging over bar options
Vladimir Bauer
1 year, 10 months ago
| 551 | 551 |
return table
|
| 552 | 552 |
}
|
| 553 | 553 |
|
| 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)
|
| 567 | 565 |
}
|
| 568 | 566 |
}
|
| 569 | 567 |
}
|
| 23 | 23 |
func PrependDecorators(decorators ...decor.Decorator) BarOption {
|
| 24 | 24 |
decorators = inspect(decorators)
|
| 25 | 25 |
return func(s *bState) {
|
|
26 |
s.sortDecorators(decorators)
|
| 26 | 27 |
s.decorators[0] = decorators
|
| 27 | 28 |
}
|
| 28 | 29 |
}
|
|
| 31 | 32 |
func AppendDecorators(decorators ...decor.Decorator) BarOption {
|
| 32 | 33 |
decorators = inspect(decorators)
|
| 33 | 34 |
return func(s *bState) {
|
|
35 |
s.sortDecorators(decorators)
|
| 34 | 36 |
s.decorators[1] = decorators
|
| 35 | 37 |
}
|
| 36 | 38 |
}
|
| 450 | 450 |
bs.buffers[1] = bytes.NewBuffer(make([]byte, 0, 128)) // append
|
| 451 | 451 |
bs.buffers[2] = bytes.NewBuffer(make([]byte, 0, 256)) // filler
|
| 452 | 452 |
|
| 453 | |
bs.sortDecorators()
|
| 454 | |
|
| 455 | 453 |
return bs
|
| 456 | 454 |
}
|