Codebase list golang-github-vbauerster-mpb / a10a752
allocate bar's buffer once Vladimir Bauer 9 years ago
1 changed file(s) with 3 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
9393 // blockStartTime := time.Now()
9494 // timePerItemEstimate time.Duration
9595 // remainingTime time.Duration
96 buf := make([]byte, b.Width)
9697 for {
9798 select {
9899 case n := <-b.currentUpdateCh:
103104 // fmt.Printf("current = %+v\n", current)
104105 // blockStartTime = time.Now()
105106 case r := <-b.redrawRequestCh:
106 r.bufch <- b.draw(current)
107 r.bufch <- b.draw(buf, current)
107108 }
108109 }
109110 }
110111
111 func (b *Bar) draw(current int) []byte {
112 func (b *Bar) draw(buf []byte, current int) []byte {
112113 completedWidth := current * b.Width / b.total
113114
114 buf := make([]byte, b.Width)
115115 for i := 0; i < completedWidth; i++ {
116116 buf[i] = b.Fill
117117 }