Skip to content

Commit 76d48fe

Browse files
committed
minor: avoid int64 -> uint conversion
1 parent 6b70ec5 commit 76d48fe

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

bar_filler_bar.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func (s *barFiller) Fill(w io.Writer, stat decor.Statistics) error {
201201
var tip component
202202
var refilling, filling, padding []byte
203203
var fillCount int
204-
curWidth := int(internal.PercentageRound(stat.Total, stat.Current, uint(width)))
204+
curWidth := int(internal.PercentageRound(stat.Total, stat.Current, int64(width)))
205205

206206
if curWidth != 0 {
207207
if !stat.Completed || s.tip.onComplete {
@@ -211,7 +211,7 @@ func (s *barFiller) Fill(w io.Writer, stat decor.Statistics) error {
211211
}
212212
switch refWidth := 0; {
213213
case stat.Refill != 0:
214-
refWidth = int(internal.PercentageRound(stat.Total, stat.Refill, uint(width)))
214+
refWidth = int(internal.PercentageRound(stat.Total, stat.Refill, int64(width)))
215215
curWidth -= refWidth
216216
refWidth += curWidth
217217
fallthrough

decor/percentage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func NewPercentage(format string, wcc ...WC) Decorator {
6161
format = "% d"
6262
}
6363
f := func(s Statistics) string {
64-
p := internal.Percentage(uint(s.Total), uint(s.Current), 100)
64+
p := internal.Percentage(s.Total, s.Current, 100)
6565
return fmt.Sprintf(format, percentageType(p))
6666
}
6767
return Any(f, wcc...)

internal/percentage.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package internal
33
import "math"
44

55
// Percentage is a helper function, to calculate percentage.
6-
func Percentage(total, current, width uint) float64 {
6+
func Percentage(total, current, width int64) float64 {
77
if total == 0 {
88
return 0
99
}
@@ -14,9 +14,9 @@ func Percentage(total, current, width uint) float64 {
1414
}
1515

1616
// PercentageRound same as Percentage but with math.Round.
17-
func PercentageRound(total, current int64, width uint) float64 {
17+
func PercentageRound(total, current, width int64) float64 {
1818
if total < 0 || current < 0 {
1919
return 0
2020
}
21-
return math.Round(Percentage(uint(total), uint(current), width))
21+
return math.Round(Percentage(total, current, width))
2222
}

internal/percentage_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "testing"
44

55
func TestPercentage(t *testing.T) {
66
// key is barWidth
7-
testSuite := map[uint][]struct {
7+
testSuite := map[int64][]struct {
88
name string
99
total int64
1010
current int64

0 commit comments

Comments
 (0)