From 252b8b8deb9dba30cc619a0d7ac14853335c37a4 Mon Sep 17 00:00:00 2001 From: Chris Howey Date: Wed, 28 Feb 2024 14:10:57 -0600 Subject: [PATCH] style: for range N --- balances_test.go | 4 ++-- decimal/decimal.go | 2 +- decimal/decimal_test.go | 6 +++--- parse_test.go | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/balances_test.go b/balances_test.go index 16773b4a..ae8ef4f6 100644 --- a/balances_test.go +++ b/balances_test.go @@ -91,7 +91,7 @@ func TestBalanceLedger(t *testing.T) { func BenchmarkGetBalances(b *testing.B) { var trans []*Transaction - for i := 0; i < 100000; i++ { + for i := range 100000 { a := rand.Intn(50) b := rand.Intn(10) c := rand.Intn(5) @@ -115,7 +115,7 @@ func BenchmarkGetBalances(b *testing.B) { }) } b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { GetBalances(trans, []string{}) } } diff --git a/decimal/decimal.go b/decimal/decimal.go index 335866e5..e3b2d842 100644 --- a/decimal/decimal.go +++ b/decimal/decimal.go @@ -214,7 +214,7 @@ func (d Decimal) Cmp(d1 Decimal) int { // output bytes begin and the value v/10**prec. func fmtFrac(buf []byte, v uint64, prec int) (nw int, nv uint64) { w := len(buf) - for i := 0; i < prec; i++ { + for range prec { digit := v % 10 w-- buf[w] = byte(digit) + '0' diff --git a/decimal/decimal_test.go b/decimal/decimal_test.go index 7fe624ec..740b65e6 100644 --- a/decimal/decimal_test.go +++ b/decimal/decimal_test.go @@ -414,7 +414,7 @@ func FuzzStringParse(f *testing.F) { func BenchmarkNewFromString(b *testing.B) { numbers := []string{"10.0", "245.6", "354", "2.456", "-31.2"} - for n := 0; n < b.N; n++ { + for range b.N { for _, numStr := range numbers { NewFromString(numStr) } @@ -423,14 +423,14 @@ func BenchmarkNewFromString(b *testing.B) { func BenchmarkStringFixedBank(b *testing.B) { var numbers [1000]Decimal - for i := 0; i < len(numbers); i++ { + for i := range len(numbers) { numbers[i] = NewFromFloat(rand.Float64() * 100000) if i%2 == 0 { numbers[i] *= -1 } } b.ResetTimer() - for n := 0; n < b.N; n++ { + for range b.N { for _, num := range numbers { num.StringFixedBank() } diff --git a/parse_test.go b/parse_test.go index c163ee74..1263550b 100644 --- a/parse_test.go +++ b/parse_test.go @@ -577,7 +577,7 @@ account endofledger`) } func BenchmarkParseLedger(b *testing.B) { - for n := 0; n < b.N; n++ { + for range b.N { _, _ = ParseLedgerFile("testdata/ledgerBench.dat") } }