allocate bar's buffer once
Vladimir Bauer
9 years ago
| 93 | 93 | // blockStartTime := time.Now() |
| 94 | 94 | // timePerItemEstimate time.Duration |
| 95 | 95 | // remainingTime time.Duration |
| 96 | buf := make([]byte, b.Width) | |
| 96 | 97 | for { |
| 97 | 98 | select { |
| 98 | 99 | case n := <-b.currentUpdateCh: |
| 103 | 104 | // fmt.Printf("current = %+v\n", current) |
| 104 | 105 | // blockStartTime = time.Now() |
| 105 | 106 | case r := <-b.redrawRequestCh: |
| 106 | r.bufch <- b.draw(current) | |
| 107 | r.bufch <- b.draw(buf, current) | |
| 107 | 108 | } |
| 108 | 109 | } |
| 109 | 110 | } |
| 110 | 111 | |
| 111 | func (b *Bar) draw(current int) []byte { | |
| 112 | func (b *Bar) draw(buf []byte, current int) []byte { | |
| 112 | 113 | completedWidth := current * b.Width / b.total |
| 113 | 114 | |
| 114 | buf := make([]byte, b.Width) | |
| 115 | 115 | for i := 0; i < completedWidth; i++ { |
| 116 | 116 | buf[i] = b.Fill |
| 117 | 117 | } |