[#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 <ekaterina.lebedeva@yadro.com>
This commit is contained in:
Ekaterina Lebedeva 2024-09-04 15:44:59 +03:00
parent 7d71556eee
commit bd588fa2e5
6 changed files with 13 additions and 13 deletions

View file

@ -32,7 +32,7 @@ func BenchmarkTable_ToGRPCMessage(b *testing.B) {
b.Run("to grpc message", func(b *testing.B) { b.Run("to grpc message", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for range b.N {
raw := tb.ToGRPCMessage() raw := tb.ToGRPCMessage()
if len(tb.GetRecords()) != len(raw.(*aclGrpc.EACLTable).Records) { if len(tb.GetRecords()) != len(raw.(*aclGrpc.EACLTable).Records) {
b.FailNow() b.FailNow()
@ -41,7 +41,7 @@ func BenchmarkTable_ToGRPCMessage(b *testing.B) {
}) })
b.Run("from grpc message", func(b *testing.B) { b.Run("from grpc message", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for range b.N {
tb := new(acl.Table) tb := new(acl.Table)
if tb.FromGRPCMessage(raw) != nil { if tb.FromGRPCMessage(raw) != nil {
b.FailNow() b.FailNow()

View file

@ -525,7 +525,7 @@ func (x *NetworkConfig) ToGRPCMessage() grpc.Message {
if ln := len(x.ps); ln > 0 { if ln := len(x.ps); ln > 0 {
ps = make([]netmap.NetworkConfig_Parameter, 0, ln) 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)) 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) ps = make([]NetworkParameter, ln)
for i := 0; i < ln; i++ { for i := range ln {
if err := ps[i].FromGRPCMessage(&psV2[i]); err != nil { if err := ps[i].FromGRPCMessage(&psV2[i]); err != nil {
return err return err
} }

View file

@ -26,7 +26,7 @@ func BenchmarkAttributesMarshal(b *testing.B) {
b.Run("marshal", func(b *testing.B) { b.Run("marshal", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for range b.N {
res := AttributesToGRPC(attrs) res := AttributesToGRPC(attrs)
if len(res) != len(raw) { if len(res) != len(raw) {
b.FailNow() b.FailNow()
@ -35,7 +35,7 @@ func BenchmarkAttributesMarshal(b *testing.B) {
}) })
b.Run("unmarshal", func(b *testing.B) { b.Run("unmarshal", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for range b.N {
res, err := AttributesFromGRPC(raw) res, err := AttributesFromGRPC(raw)
if err != nil || len(res) != len(raw) { if err != nil || len(res) != len(raw) {
b.FailNow() b.FailNow()

View file

@ -24,7 +24,7 @@ func benchmarkObjectIDSlice(b *testing.B, size int) {
b.Run("to grpc message", func(b *testing.B) { b.Run("to grpc message", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for range b.N {
raw := ObjectIDListToGRPCMessage(ids) raw := ObjectIDListToGRPCMessage(ids)
if len(raw) != len(ids) { if len(raw) != len(ids) {
b.FailNow() b.FailNow()
@ -33,7 +33,7 @@ func benchmarkObjectIDSlice(b *testing.B, size int) {
}) })
b.Run("from grpc message", func(b *testing.B) { b.Run("from grpc message", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for range b.N {
ids, err := ObjectIDListFromGRPCMessage(raw) ids, err := ObjectIDListFromGRPCMessage(raw)
if err != nil || len(raw) != len(ids) { if err != nil || len(raw) != len(ids) {
b.FailNow() b.FailNow()
@ -42,7 +42,7 @@ func benchmarkObjectIDSlice(b *testing.B, size int) {
}) })
b.Run("marshal", func(b *testing.B) { b.Run("marshal", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for range b.N {
buf := make([]byte, ObjectIDNestedListSize(1, ids)) buf := make([]byte, ObjectIDNestedListSize(1, ids))
n := ObjectIDNestedListMarshal(1, buf, ids) n := ObjectIDNestedListMarshal(1, buf, ids)
if n != len(buf) { if n != len(buf) {

View file

@ -77,7 +77,7 @@ func BenchmarkSignRequest(b *testing.B) {
b.ResetTimer() b.ResetTimer()
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for range b.N {
b.StopTimer() b.StopTimer()
dec := new(accounting.Decimal) dec := new(accounting.Decimal)
dec.SetValue(100) dec.SetValue(100)
@ -103,7 +103,7 @@ func BenchmarkVerifyRequest(b *testing.B) {
b.ResetTimer() b.ResetTimer()
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for range b.N {
b.StopTimer() b.StopTimer()
dec := new(accounting.Decimal) dec := new(accounting.Decimal)
dec.SetValue(100) dec.SetValue(100)

View file

@ -53,7 +53,7 @@ func (x *Status) ToGRPCMessage() grpc.Message {
if ln := len(x.details); ln > 0 { if ln := len(x.details); ln > 0 {
ds = make([]status.Status_Detail, 0, ln) 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)) 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) ds = make([]Detail, ln)
for i := 0; i < ln; i++ { for i := range ln {
if err := ds[i].FromGRPCMessage(&dsV2[i]); err != nil { if err := ds[i].FromGRPCMessage(&dsV2[i]); err != nil {
return err return err
} }