all: use Go 1.22 range-over-int

Updates #11058

Change-Id: I35e7ef9b90e83cac04ca93fd964ad00ed5b48430
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2024-04-16 13:15:13 -07:00
committed by Brad Fitzpatrick
parent 068db1f972
commit 7c1d6e35a5
143 changed files with 280 additions and 282 deletions
+5 -5
View File
@@ -49,7 +49,7 @@ func TestAcceptedNamesContainsPreferredNames(t *testing.T) {
}
func TestProtoTextEncodingRoundTrip(t *testing.T) {
for i := 0; i < 256; i++ {
for i := range 256 {
text := must.Get(Proto(i).MarshalText())
var p Proto
must.Do(p.UnmarshalText(text))
@@ -67,7 +67,7 @@ func TestProtoUnmarshalText(t *testing.T) {
t.Fatalf("empty input, got err=%v, p=%v, want nil, 0", err, p)
}
for i := 0; i < 256; i++ {
for i := range 256 {
var p Proto
must.Do(p.UnmarshalText([]byte(fmt.Sprintf("%d", i))))
if got, want := p, Proto(i); got != want {
@@ -93,7 +93,7 @@ func TestProtoUnmarshalText(t *testing.T) {
}
func TestProtoMarshalText(t *testing.T) {
for i := 0; i < 256; i++ {
for i := range 256 {
text := must.Get(Proto(i).MarshalText())
if wantName, ok := preferredNames[Proto(i)]; ok {
@@ -110,7 +110,7 @@ func TestProtoMarshalText(t *testing.T) {
}
func TestProtoMarshalJSON(t *testing.T) {
for i := 0; i < 256; i++ {
for i := range 256 {
j := must.Get(Proto(i).MarshalJSON())
if got, want := string(j), fmt.Sprintf(`%d`, i); got != want {
t.Errorf("Proto(%d).MarshalJSON() = %q, want %q", i, got, want)
@@ -121,7 +121,7 @@ func TestProtoMarshalJSON(t *testing.T) {
func TestProtoUnmarshalJSON(t *testing.T) {
var p Proto
for i := 0; i < 256; i++ {
for i := range 256 {
j := []byte(fmt.Sprintf(`%d`, i))
must.Do(json.Unmarshal(j, &p))
if got, want := p, Proto(i); got != want {
+1 -1
View File
@@ -162,7 +162,7 @@ func TestChallenge(t *testing.T) {
func TestShard(t *testing.T) {
const N = 1_000
var shardCount [256]int
for i := 0; i < N; i++ {
for range N {
shardCount[NewNode().Public().Shard()]++
}
e := float64(N) / 256 // expected
+1 -1
View File
@@ -22,7 +22,7 @@ func TestRand(t *testing.T) {
}
func TestClamp25519Private(t *testing.T) {
for i := 0; i < 100; i++ {
for range 100 {
var k [32]byte
rand(k[:])
clamp25519Private(k[:])
+1 -1
View File
@@ -89,7 +89,7 @@ func TestSyncValueConcurrent(t *testing.T) {
routines = 10000
)
wg.Add(routines)
for i := 0; i < routines; i++ {
for range routines {
go func() {
defer wg.Done()
// Every goroutine waits for the go signal, so that more of them
+2 -2
View File
@@ -70,7 +70,7 @@ func TestRateLimiter(t *testing.T) {
lgtest := logTester(want, t, &testsRun)
lg := RateLimitedFnWithClock(lgtest, 1*time.Minute, 2, 50, nowf)
var prefixed Logf
for i := 0; i < 10; i++ {
for i := range 10 {
lg("boring string with constant formatting %s", "(constant)")
lg("templated format string no. %d", i)
if i == 4 {
@@ -121,7 +121,7 @@ func TestLogOnChange(t *testing.T) {
lgtest := logTester(want, t, &testsRun)
lg := LogOnChange(lgtest, 5*time.Second, timeNow)
for i := 0; i < 10; i++ {
for range 10 {
lg("%s", "1 2 3 4 5 6")
}
lg("1 2 3 4 5 7")
+1 -1
View File
@@ -137,7 +137,7 @@ func (nm *NetworkMap) PeerByTailscaleIP(ip netip.Addr) (peer tailcfg.NodeView, o
}
for _, n := range nm.Peers {
ad := n.Addresses()
for i := 0; i < ad.Len(); i++ {
for i := range ad.Len() {
a := ad.At(i)
if a.Addr() == ip {
return n, true
+1 -1
View File
@@ -73,7 +73,7 @@ func (m NodeMutationLastSeen) Apply(n *tailcfg.Node) {
var peerChangeFields = sync.OnceValue(func() []reflect.StructField {
var fields []reflect.StructField
rt := reflect.TypeFor[tailcfg.PeerChange]()
for i := 0; i < rt.NumField(); i++ {
for i := range rt.NumField() {
fields = append(fields, rt.Field(i))
}
return fields
+1 -1
View File
@@ -44,7 +44,7 @@ func TestMapResponseContainsNonPatchFields(t *testing.T) {
}
rt := reflect.TypeFor[tailcfg.MapResponse]()
for i := 0; i < rt.NumField(); i++ {
for i := range rt.NumField() {
f := rt.Field(i)
var want bool
+1 -1
View File
@@ -12,7 +12,7 @@ import (
)
func fieldsOf(t reflect.Type) (fields []string) {
for i := 0; i < t.NumField(); i++ {
for i := range t.NumField() {
if name := t.Field(i).Name; name != "_" {
fields = append(fields, name)
}
+1 -1
View File
@@ -262,7 +262,7 @@ func (v Slice[T]) AsSlice() []T {
//
// As it runs in O(n) time, use with care.
func (v Slice[T]) IndexFunc(f func(T) bool) int {
for i := 0; i < v.Len(); i++ {
for i := range v.Len() {
if f(v.At(i)) {
return i
}
+3 -3
View File
@@ -24,7 +24,7 @@ type viewStruct struct {
func BenchmarkSliceIteration(b *testing.B) {
var data []viewStruct
for i := 0; i < 10000; i++ {
for i := range 10000 {
data = append(data, viewStruct{Int: i})
}
b.ResetTimer()
@@ -33,7 +33,7 @@ func BenchmarkSliceIteration(b *testing.B) {
dv := SliceOf(data)
for it := 0; it < b.N; it++ {
sum := 0
for i := 0; i < dv.Len(); i++ {
for i := range dv.Len() {
sum += dv.At(i).Int
}
}
@@ -181,7 +181,7 @@ func TestSliceMapKey(t *testing.T) {
}
wantDiff := []Slice[string]{nilSlice, empty, sub1, sub2, sub3, u3}
for i := 0; i < len(wantDiff); i++ {
for i := range len(wantDiff) {
for j := i + 1; j < len(wantDiff); j++ {
si, sj := wantDiff[i], wantDiff[j]
ki, kj := wantDiff[i].MapKey(), wantDiff[j].MapKey()