Skip to content

Commit 09e4187

Browse files
authored
modernize (#1764)
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix ./...
1 parent 6c44a9a commit 09e4187

13 files changed

Lines changed: 43 additions & 50 deletions

benchmark_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func benchmarkQuery(b *testing.B, compr bool) {
9292
defer wg.Wait()
9393
b.StartTimer()
9494

95-
for i := 0; i < concurrencyLevel; i++ {
95+
for range concurrencyLevel {
9696
go func() {
9797
for {
9898
if atomic.AddInt64(&remain, -1) < 0 {
@@ -129,7 +129,7 @@ func BenchmarkExec(b *testing.B) {
129129
b.ReportAllocs()
130130
b.ResetTimer()
131131

132-
for i := 0; i < concurrencyLevel; i++ {
132+
for range concurrencyLevel {
133133
go func() {
134134
for {
135135
if atomic.AddInt64(&remain, -1) < 0 {
@@ -164,10 +164,9 @@ func BenchmarkRoundtripTxt(b *testing.B) {
164164
defer db.Close()
165165

166166
b.ReportAllocs()
167-
b.ResetTimer()
168167

169168
var result string
170-
for i := 0; i < b.N; i++ {
169+
for i := 0; b.Loop(); i++ {
171170
length := min + i
172171
if length > max {
173172
length = max
@@ -200,9 +199,9 @@ func BenchmarkRoundtripBin(b *testing.B) {
200199
defer stmt.Close()
201200

202201
b.ReportAllocs()
203-
b.ResetTimer()
202+
204203
var result sql.RawBytes
205-
for i := 0; i < b.N; i++ {
204+
for i := 0; b.Loop(); i++ {
206205
length := min + i
207206
if length > max {
208207
length = max
@@ -248,8 +247,8 @@ func BenchmarkInterpolation(b *testing.B) {
248247
q := "SELECT ?, ?, ?, ?, ?, ?"
249248

250249
b.ReportAllocs()
251-
b.ResetTimer()
252-
for i := 0; i < b.N; i++ {
250+
251+
for b.Loop() {
253252
_, err := mc.interpolateParams(q, args)
254253
if err != nil {
255254
b.Fatal(err)
@@ -345,7 +344,7 @@ func BenchmarkQueryRawBytes(b *testing.B) {
345344
for i := range blob {
346345
blob[i] = 42
347346
}
348-
for i := 0; i < 100; i++ {
347+
for i := range 100 {
349348
_, err := db.Exec("INSERT INTO bench_rawbytes VALUES (?, ?)", i, blob)
350349
if err != nil {
351350
b.Fatal(err)
@@ -404,7 +403,7 @@ func benchmark10kRows(b *testing.B, compress bool) {
404403
args[i] = sval
405404
}
406405
for i := 0; i < 10000; i += 100 {
407-
for j := 0; j < 100; j++ {
406+
for j := range 100 {
408407
args[j*2] = i + j
409408
}
410409
_, err := stmt.Exec(args...)
@@ -461,19 +460,20 @@ func BenchmarkReceiveMetadata(b *testing.B) {
461460
tb := (*TB)(b)
462461

463462
// Create a table with 1000 integer fields
464-
createTableQuery := "CREATE TABLE large_integer_table ("
465-
for i := 0; i < 1000; i++ {
466-
createTableQuery += fmt.Sprintf("col_%d INT", i)
463+
var createTableQuery strings.Builder
464+
createTableQuery.WriteString("CREATE TABLE large_integer_table (")
465+
for i := range 1000 {
466+
createTableQuery.WriteString(fmt.Sprintf("col_%d INT", i))
467467
if i < 999 {
468-
createTableQuery += ", "
468+
createTableQuery.WriteString(", ")
469469
}
470470
}
471-
createTableQuery += ")"
471+
createTableQuery.WriteString(")")
472472

473473
// Initialize database
474474
db := initDB(b, false,
475475
"DROP TABLE IF EXISTS large_integer_table",
476-
createTableQuery,
476+
createTableQuery.String(),
477477
"INSERT INTO large_integer_table VALUES ("+
478478
strings.Repeat("0,", 999)+"0)", // Insert a row of zeros
479479
)

conncheck.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// You can obtain one at http://mozilla.org/MPL/2.0/.
88

99
//go:build linux || darwin || dragonfly || freebsd || netbsd || openbsd || solaris || illumos
10-
// +build linux darwin dragonfly freebsd netbsd openbsd solaris illumos
1110

1211
package mysql
1312

conncheck_dummy.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// You can obtain one at http://mozilla.org/MPL/2.0/.
88

99
//go:build !linux && !darwin && !dragonfly && !freebsd && !netbsd && !openbsd && !solaris && !illumos
10-
// +build !linux,!darwin,!dragonfly,!freebsd,!netbsd,!openbsd,!solaris,!illumos
1110

1211
package mysql
1312

conncheck_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// You can obtain one at http://mozilla.org/MPL/2.0/.
88

99
//go:build linux || darwin || dragonfly || freebsd || netbsd || openbsd || solaris || illumos
10-
// +build linux darwin dragonfly freebsd netbsd openbsd solaris illumos
1110

1211
package mysql
1312

connection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (strin
282282
lenQuery := len(query)
283283
lastIdx := 0
284284

285-
for i := 0; i < lenQuery; i++ {
285+
for i := range lenQuery {
286286
currentChar := query[i]
287287
if state == stateEscape && !((currentChar == QUOTE_BYTE && singleQuotes) || (currentChar == DBL_QUOTE_BYTE && !singleQuotes)) {
288288
state = stateString

connector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func encodeConnectionAttributes(cfg *Config) string {
4242
}
4343

4444
// user-defined connection attributes
45-
for _, connAttr := range strings.Split(cfg.ConnectionAttributes, ",") {
45+
for connAttr := range strings.SplitSeq(cfg.ConnectionAttributes, ",") {
4646
k, v, found := strings.Cut(connAttr, ":")
4747
if !found {
4848
continue

driver_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ func runTests(t *testing.T, dsn string, tests ...func(dbt *DBTest)) {
176176
cleanupSql := "DROP TABLE IF EXISTS test"
177177

178178
for _, test := range tests {
179-
test := test
180179
t.Run("default", func(t *testing.T) {
181180
dbt := &DBTest{t, db}
182181
t.Cleanup(func() {
@@ -220,7 +219,6 @@ func runTestsParallel(t *testing.T, dsn string, tests ...func(dbt *DBTest, table
220219

221220
t.Parallel()
222221
for _, test := range tests {
223-
test := test
224222

225223
t.Run("default", func(t *testing.T) {
226224
t.Parallel()

dsn.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"crypto/tls"
1616
"errors"
1717
"fmt"
18+
"maps"
1819
"math/big"
1920
"net"
2021
"net/url"
@@ -157,9 +158,7 @@ func (cfg *Config) Clone() *Config {
157158
}
158159
if len(cp.Params) > 0 {
159160
cp.Params = make(map[string]string, len(cfg.Params))
160-
for k, v := range cfg.Params {
161-
cp.Params[k] = v
162-
}
161+
maps.Copy(cp.Params, cfg.Params)
163162
}
164163
if cfg.pubKey != nil {
165164
cp.pubKey = &rsa.PublicKey{
@@ -477,7 +476,7 @@ func ParseDSN(dsn string) (cfg *Config, err error) {
477476
// parseDSNParams parses the DSN "query string"
478477
// Values must be url.QueryEscape'ed
479478
func parseDSNParams(cfg *Config, params string) (err error) {
480-
for _, v := range strings.Split(params, "&") {
479+
for v := range strings.SplitSeq(params, "&") {
481480
key, value, found := strings.Cut(v, "=")
482481
if !found {
483482
continue

dsn_fuzz_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build go1.18
2-
// +build go1.18
32

43
package mysql
54

dsn_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func TestNormalizeTLSConfig(t *testing.T) {
432432
func BenchmarkParseDSN(b *testing.B) {
433433
b.ReportAllocs()
434434

435-
for i := 0; i < b.N; i++ {
435+
for b.Loop() {
436436
for _, tst := range testDSNs {
437437
if _, err := ParseDSN(tst.in); err != nil {
438438
b.Error(err.Error())

0 commit comments

Comments
 (0)