Skip to content

Commit 04650ce

Browse files
committed
all: Run modernize -fix ./...
Closes #14107
1 parent 264022a commit 04650ce

File tree

122 files changed

+275
-351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+275
-351
lines changed

‎cache/httpcache/httpcache_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestDefaultConfig(t *testing.T) {
5252
func TestDecodeConfigInjectsDefaultAndCompiles(t *testing.T) {
5353
c := qt.New(t)
5454

55-
cfg, err := DecodeConfig(config.BaseConfig{}, map[string]interface{}{})
55+
cfg, err := DecodeConfig(config.BaseConfig{}, map[string]any{})
5656
c.Assert(err, qt.IsNil)
5757
c.Assert(cfg, qt.DeepEquals, DefaultConfig)
5858

‎commands/server.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,6 @@ func (c *serverCommand) serve() error {
10351035
defer cancel()
10361036
wg2, ctx := errgroup.WithContext(ctx)
10371037
for _, srv := range servers {
1038-
srv := srv
10391038
wg2.Go(func() error {
10401039
return srv.Shutdown(ctx)
10411040
})

‎common/hashing/hashing_test.go‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ func TestXxHashFromReaderPara(t *testing.T) {
3838

3939
var wg sync.WaitGroup
4040
for i := range 10 {
41-
i := i
4241
wg.Add(1)
4342
go func() {
4443
defer wg.Done()
@@ -75,25 +74,25 @@ func TestXxHashFromStringHexEncoded(t *testing.T) {
7574

7675
func BenchmarkXXHashFromReader(b *testing.B) {
7776
r := strings.NewReader("Hello World")
78-
b.ResetTimer()
79-
for i := 0; i < b.N; i++ {
77+
78+
for b.Loop() {
8079
XXHashFromReader(r)
8180
r.Seek(0, 0)
8281
}
8382
}
8483

8584
func BenchmarkXXHashFromString(b *testing.B) {
8685
s := "Hello World"
87-
b.ResetTimer()
88-
for i := 0; i < b.N; i++ {
86+
87+
for b.Loop() {
8988
XXHashFromString(s)
9089
}
9190
}
9291

9392
func BenchmarkXXHashFromStringHexEncoded(b *testing.B) {
9493
s := "The quick brown fox jumps over the lazy dog"
95-
b.ResetTimer()
96-
for i := 0; i < b.N; i++ {
94+
95+
for b.Loop() {
9796
XxHashFromStringHexEncoded(s)
9897
}
9998
}
@@ -136,7 +135,7 @@ func BenchmarkHashString(b *testing.B) {
136135

137136
for _, test := range tests {
138137
b.Run(fmt.Sprintf("n%d", len(test)), func(b *testing.B) {
139-
for i := 0; i < b.N; i++ {
138+
for b.Loop() {
140139
HashString(test)
141140
}
142141
})
@@ -149,9 +148,7 @@ func BenchmarkHashMap(b *testing.B) {
149148
m[fmt.Sprintf("key%d", i)] = i
150149
}
151150

152-
b.ResetTimer()
153-
154-
for i := 0; i < b.N; i++ {
151+
for b.Loop() {
155152
HashString(m)
156153
}
157154
}

‎common/hreflect/convert_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func TestConvertIfPossibleMisc(t *testing.T) {
278278

279279
func BenchmarkToInt64(b *testing.B) {
280280
v := reflect.ValueOf(int(42))
281-
for i := 0; i < b.N; i++ {
281+
for b.Loop() {
282282
ToInt64(v)
283283
}
284284
}

‎common/hreflect/helpers_test.go‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ func BenchmarkIsContextType(b *testing.B) {
156156
b.Run("value", func(b *testing.B) {
157157
ctx := context.Background()
158158
ctxs := make([]reflect.Type, b.N)
159-
for i := 0; i < b.N; i++ {
159+
for i := 0; b.Loop(); i++ {
160160
ctxs[i] = reflect.TypeOf(context.WithValue(ctx, k("key"), i))
161161
}
162162

163163
b.ResetTimer()
164-
for i := 0; i < b.N; i++ {
164+
for i := 0; b.Loop(); i++ {
165165
if !IsContextType(ctxs[i]) {
166166
b.Fatal("not context")
167167
}
@@ -170,7 +170,7 @@ func BenchmarkIsContextType(b *testing.B) {
170170

171171
b.Run("background", func(b *testing.B) {
172172
var ctxt reflect.Type = reflect.TypeOf(context.Background())
173-
for i := 0; i < b.N; i++ {
173+
for b.Loop() {
174174
if !IsContextType(ctxt) {
175175
b.Fatal("not context")
176176
}
@@ -189,8 +189,7 @@ func BenchmarkIsTruthFulValue(b *testing.B) {
189189
nilPointer = reflect.ValueOf((*zeroStruct)(nil))
190190
)
191191

192-
b.ResetTimer()
193-
for i := 0; i < b.N; i++ {
192+
for b.Loop() {
194193
IsTruthfulValue(stringHugo)
195194
IsTruthfulValue(stringEmpty)
196195
IsTruthfulValue(zero)
@@ -227,8 +226,7 @@ func BenchmarkGetMethodByNameForType(b *testing.B) {
227226
tp := reflect.TypeFor[*testStruct]()
228227
methods := []string{"Method1", "Method2", "Method3", "Method4", "Method5"}
229228

230-
b.ResetTimer()
231-
for i := 0; i < b.N; i++ {
229+
for b.Loop() {
232230
for _, method := range methods {
233231
_ = GetMethodByNameForType(tp, method)
234232
}
@@ -239,8 +237,7 @@ func BenchmarkGetMethodByName(b *testing.B) {
239237
v := reflect.ValueOf(&testStruct{})
240238
methods := []string{"Method1", "Method2", "Method3", "Method4", "Method5"}
241239

242-
b.ResetTimer()
243-
for i := 0; i < b.N; i++ {
240+
for b.Loop() {
244241
for _, method := range methods {
245242
_ = GetMethodByName(v, method)
246243
}

‎common/hstore/scratch_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ func TestScratchGetSortedMapValues(t *testing.T) {
214214
func BenchmarkScratchGet(b *testing.B) {
215215
scratch := NewScratch()
216216
scratch.Add("A", 1)
217-
b.ResetTimer()
218-
for i := 0; i < b.N; i++ {
217+
218+
for b.Loop() {
219219
scratch.Get("A")
220220
}
221221
}

‎common/hstrings/strings_test.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func BenchmarkUniqueStrings(b *testing.B) {
7575
input := []string{"a", "b", "d", "e", "d", "h", "a", "i"}
7676

7777
b.Run("Safe", func(b *testing.B) {
78-
for i := 0; i < b.N; i++ {
78+
for b.Loop() {
7979
result := UniqueStrings(input)
8080
if len(result) != 6 {
8181
b.Fatalf("invalid count: %d", len(result))
@@ -86,13 +86,13 @@ func BenchmarkUniqueStrings(b *testing.B) {
8686
b.Run("Reuse slice", func(b *testing.B) {
8787
b.StopTimer()
8888
inputs := make([][]string, b.N)
89-
for i := 0; i < b.N; i++ {
89+
for i := 0; b.Loop(); i++ {
9090
inputc := make([]string, len(input))
9191
copy(inputc, input)
9292
inputs[i] = inputc
9393
}
9494
b.StartTimer()
95-
for i := 0; i < b.N; i++ {
95+
for i := 0; b.Loop(); i++ {
9696
inputc := inputs[i]
9797

9898
result := UniqueStringsReuse(inputc)
@@ -105,13 +105,13 @@ func BenchmarkUniqueStrings(b *testing.B) {
105105
b.Run("Reuse slice sorted", func(b *testing.B) {
106106
b.StopTimer()
107107
inputs := make([][]string, b.N)
108-
for i := 0; i < b.N; i++ {
108+
for i := 0; b.Loop(); i++ {
109109
inputc := make([]string, len(input))
110110
copy(inputc, input)
111111
inputs[i] = inputc
112112
}
113113
b.StartTimer()
114-
for i := 0; i < b.N; i++ {
114+
for i := 0; b.Loop(); i++ {
115115
inputc := inputs[i]
116116

117117
result := UniqueStringsSorted(inputc)
@@ -123,13 +123,13 @@ func BenchmarkUniqueStrings(b *testing.B) {
123123
}
124124

125125
func BenchmarkGetOrCompileRegexp(b *testing.B) {
126-
for i := 0; i < b.N; i++ {
126+
for b.Loop() {
127127
GetOrCompileRegexp(`\d+`)
128128
}
129129
}
130130

131131
func BenchmarkCompileRegexp(b *testing.B) {
132-
for i := 0; i < b.N; i++ {
132+
for b.Loop() {
133133
regexp.MustCompile(`\d+`)
134134
}
135135
}

‎common/hsync/oncemore_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func BenchmarkOnceMoreValue(b *testing.B) {
6767
return counter
6868
}
6969

70-
for range b.N {
70+
for b.Loop() {
7171
omf := OnceMoreValue(f)
7272
for range 10 {
7373
omf.Value(context.Background())

‎common/htime/time_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func BenchmarkTimeFormatter(b *testing.B) {
112112
june06, _ := time.Parse("2006-Jan-02", "2018-Jun-06")
113113

114114
b.Run("Native", func(b *testing.B) {
115-
for i := 0; i < b.N; i++ {
115+
for b.Loop() {
116116
got := june06.Format("Monday Jan 2 2006")
117117
if got != "Wednesday Jun 6 2018" {
118118
b.Fatalf("invalid format, got %q", got)
@@ -123,7 +123,7 @@ func BenchmarkTimeFormatter(b *testing.B) {
123123
b.Run("Localized", func(b *testing.B) {
124124
f := NewTimeFormatter(translators.GetTranslator("nn"))
125125
b.ResetTimer()
126-
for i := 0; i < b.N; i++ {
126+
for b.Loop() {
127127
got := f.Format(june06, "Monday Jan 2 2006")
128128
if got != "onsdag juni 6 2018" {
129129
b.Fatalf("invalid format, got %q", got)
@@ -134,7 +134,7 @@ func BenchmarkTimeFormatter(b *testing.B) {
134134
b.Run("Localized Custom", func(b *testing.B) {
135135
f := NewTimeFormatter(translators.GetTranslator("nn"))
136136
b.ResetTimer()
137-
for i := 0; i < b.N; i++ {
137+
for b.Loop() {
138138
got := f.Format(june06, ":date_medium")
139139
if got != "6. juni 2018" {
140140
b.Fatalf("invalid format, got %q", got)

‎common/maps/cache_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestCacheSize(t *testing.T) {
2424

2525
cache := NewCacheWithOptions[string, string](CacheOptions{Size: 10})
2626

27-
for i := 0; i < 30; i++ {
27+
for i := range 30 {
2828
cache.Set(string(rune('a'+i)), "value")
2929
}
3030

0 commit comments

Comments
 (0)