From bd588fa2e5d1c2d398f1f602692b867dcca154a1 Mon Sep 17 00:00:00 2001 From: Ekaterina Lebedeva Date: Wed, 4 Sep 2024 15:44:59 +0300 Subject: [PATCH] [#113] go.mod: Use range over int Since Go 1.22 a `for` statement with a `range` clause is able to iterate through integer values from zero to an upper limit. gopatch script: @@ var i, e expression @@ -for i := 0; i <= e - 1; i++ { +for i := range e { ... } @@ var i, e expression @@ -for i := 0; i <= e; i++ { +for i := range e + 1 { ... } @@ var i, e expression @@ -for i := 0; i < e; i++ { +for i := range e { ... } Signed-off-by: Ekaterina Lebedeva --- acl/bench_test.go | 4 ++-- netmap/convert.go | 4 ++-- object/bench_test.go | 4 ++-- refs/bench_test.go | 6 +++--- signature/sign_test.go | 4 ++-- status/convert.go | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/acl/bench_test.go b/acl/bench_test.go index 8d6352b..85dbf7d 100644 --- a/acl/bench_test.go +++ b/acl/bench_test.go @@ -32,7 +32,7 @@ func BenchmarkTable_ToGRPCMessage(b *testing.B) { b.Run("to grpc message", func(b *testing.B) { b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { raw := tb.ToGRPCMessage() if len(tb.GetRecords()) != len(raw.(*aclGrpc.EACLTable).Records) { b.FailNow() @@ -41,7 +41,7 @@ func BenchmarkTable_ToGRPCMessage(b *testing.B) { }) b.Run("from grpc message", func(b *testing.B) { b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { tb := new(acl.Table) if tb.FromGRPCMessage(raw) != nil { b.FailNow() diff --git a/netmap/convert.go b/netmap/convert.go index 659b798..bae309f 100644 --- a/netmap/convert.go +++ b/netmap/convert.go @@ -525,7 +525,7 @@ func (x *NetworkConfig) ToGRPCMessage() grpc.Message { if ln := len(x.ps); ln > 0 { ps = make([]netmap.NetworkConfig_Parameter, 0, ln) - for i := 0; i < ln; i++ { + for i := range ln { ps = append(ps, *x.ps[i].ToGRPCMessage().(*netmap.NetworkConfig_Parameter)) } } @@ -552,7 +552,7 @@ func (x *NetworkConfig) FromGRPCMessage(m grpc.Message) error { ps = make([]NetworkParameter, ln) - for i := 0; i < ln; i++ { + for i := range ln { if err := ps[i].FromGRPCMessage(&psV2[i]); err != nil { return err } diff --git a/object/bench_test.go b/object/bench_test.go index 90fab73..b29b1d1 100644 --- a/object/bench_test.go +++ b/object/bench_test.go @@ -26,7 +26,7 @@ func BenchmarkAttributesMarshal(b *testing.B) { b.Run("marshal", func(b *testing.B) { b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { res := AttributesToGRPC(attrs) if len(res) != len(raw) { b.FailNow() @@ -35,7 +35,7 @@ func BenchmarkAttributesMarshal(b *testing.B) { }) b.Run("unmarshal", func(b *testing.B) { b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { res, err := AttributesFromGRPC(raw) if err != nil || len(res) != len(raw) { b.FailNow() diff --git a/refs/bench_test.go b/refs/bench_test.go index b24e674..40784c6 100644 --- a/refs/bench_test.go +++ b/refs/bench_test.go @@ -24,7 +24,7 @@ func benchmarkObjectIDSlice(b *testing.B, size int) { b.Run("to grpc message", func(b *testing.B) { b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { raw := ObjectIDListToGRPCMessage(ids) if len(raw) != len(ids) { b.FailNow() @@ -33,7 +33,7 @@ func benchmarkObjectIDSlice(b *testing.B, size int) { }) b.Run("from grpc message", func(b *testing.B) { b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { ids, err := ObjectIDListFromGRPCMessage(raw) if err != nil || len(raw) != len(ids) { b.FailNow() @@ -42,7 +42,7 @@ func benchmarkObjectIDSlice(b *testing.B, size int) { }) b.Run("marshal", func(b *testing.B) { b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { buf := make([]byte, ObjectIDNestedListSize(1, ids)) n := ObjectIDNestedListMarshal(1, buf, ids) if n != len(buf) { diff --git a/signature/sign_test.go b/signature/sign_test.go index c013525..b606c27 100644 --- a/signature/sign_test.go +++ b/signature/sign_test.go @@ -77,7 +77,7 @@ func BenchmarkSignRequest(b *testing.B) { b.ResetTimer() b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { b.StopTimer() dec := new(accounting.Decimal) dec.SetValue(100) @@ -103,7 +103,7 @@ func BenchmarkVerifyRequest(b *testing.B) { b.ResetTimer() b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { b.StopTimer() dec := new(accounting.Decimal) dec.SetValue(100) diff --git a/status/convert.go b/status/convert.go index 3c5b5bf..6b34084 100644 --- a/status/convert.go +++ b/status/convert.go @@ -53,7 +53,7 @@ func (x *Status) ToGRPCMessage() grpc.Message { if ln := len(x.details); ln > 0 { ds = make([]status.Status_Detail, 0, ln) - for i := 0; i < ln; i++ { + for i := range ln { ds = append(ds, *x.details[i].ToGRPCMessage().(*status.Status_Detail)) } } @@ -80,7 +80,7 @@ func (x *Status) FromGRPCMessage(m grpc.Message) error { ds = make([]Detail, ln) - for i := 0; i < ln; i++ { + for i := range ln { if err := ds[i].FromGRPCMessage(&dsV2[i]); err != nil { return err }