Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 879eb11

Browse files
authored
modernize for Go 1.22 (#1695)
$ go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix ./...
1 parent c84f49d commit 879eb11

File tree

8 files changed

+27
-30
lines changed

8 files changed

+27
-30
lines changed

‎benchmark_test.go

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

96-
for i:=0; i<concurrencyLevel; i++ {
96+
for rangeconcurrencyLevel {
9797
go func() {
9898
for {
9999
if atomic.AddInt64(&remain, -1) < 0 {
@@ -130,7 +130,7 @@ func BenchmarkExec(b *testing.B) {
130130
defer wg.Wait()
131131
b.StartTimer()
132132

133-
for i:=0; i<concurrencyLevel; i++ {
133+
for rangeconcurrencyLevel {
134134
go func() {
135135
for {
136136
if atomic.AddInt64(&remain, -1) < 0 {
@@ -345,7 +345,7 @@ func BenchmarkQueryRawBytes(b *testing.B) {
345345
for i := range blob {
346346
blob[i] = 42
347347
}
348-
for i := 0; i<100; i++ {
348+
for i := range100 {
349349
_, err := db.Exec("INSERT INTO bench_rawbytes VALUES (?, ?)", i, blob)
350350
if err != nil {
351351
b.Fatal(err)
@@ -401,7 +401,7 @@ func BenchmarkReceiveMassiveRows(b *testing.B) {
401401
}
402402
for i := 0; i < 10000; i += 100 {
403403
args := make([]any, 200)
404-
for j := 0; j<100; j++ {
404+
for j := range100 {
405405
args[j*2] = i + j
406406
args[j*2+1] = sval
407407
}

‎connection_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func TestCleanCancel(t *testing.T) {
141141
ctx, cancel := context.WithCancel(context.Background())
142142
cancel()
143143

144-
for i:=0; i<3; i++ { // Repeat same behavior
144+
for range3 { // Repeat same behavior
145145
err := mc.Ping(ctx)
146146
if err != context.Canceled {
147147
t.Errorf("expected context.Canceled, got %#v", err)

‎driver_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"os"
2727
"reflect"
2828
"runtime"
29+
"slices"
2930
"strconv"
3031
"strings"
3132
"sync"
@@ -1926,7 +1927,7 @@ func TestPreparedManyCols(t *testing.T) {
19261927
rows.Close()
19271928

19281929
// Create 0byte string which we can't send via STMT_LONG_DATA.
1929-
for i := 0; i<numParams; i++ {
1930+
for i := rangenumParams {
19301931
params[i] = ""
19311932
}
19321933
rows, err = stmt.Query(params...)
@@ -1971,7 +1972,7 @@ func TestConcurrent(t *testing.T) {
19711972
})
19721973
}
19731974

1974-
for i := 0; i<max; i++ {
1975+
for i := rangemax {
19751976
go func(id int) {
19761977
defer wg.Done()
19771978

@@ -2355,7 +2356,7 @@ func TestPing(t *testing.T) {
23552356
q.Close()
23562357

23572358
// Verify that Ping() clears both fields.
2358-
for i:=0; i<2; i++ {
2359+
for range2 {
23592360
if err := c.Ping(ctx); err != nil {
23602361
dbt.fail("Pinger", "Ping", err)
23612362
}
@@ -2558,7 +2559,7 @@ func TestMultiResultSet(t *testing.T) {
25582559
}
25592560
defer stmt.Close()
25602561

2561-
for j := 0; j<2; j++ {
2562+
for j := range2 {
25622563
rows, err := stmt.Query()
25632564
if err != nil {
25642565
dbt.Fatalf("%v (i=%d) (j=%d)", err, i, j)
@@ -2665,7 +2666,7 @@ func TestQueryMultipleResults(t *testing.T) {
26652666
c := conn.(*mysqlConn)
26662667

26672668
// Demonstrate that repeated queries reset the affectedRows
2668-
for i:=0; i<2; i++ {
2669+
for range2 {
26692670
_, err := qr.Query(`
26702671
INSERT INTO test (value) VALUES ('a'), ('b');
26712672
INSERT INTO test (value) VALUES ('c'), ('d'), ('e');
@@ -3293,11 +3294,11 @@ func TestRawBytesAreNotModified(t *testing.T) {
32933294

32943295
runTests(t, dsn, func(dbt *DBTest) {
32953296
dbt.mustExec("CREATE TABLE test (id int, value BLOB) CHARACTER SET utf8")
3296-
for i := 0; i<insertRows; i++ {
3297+
for i := rangeinsertRows {
32973298
dbt.mustExec("INSERT INTO test VALUES (?, ?)", i+1, sqlBlobs[i&1])
32983299
}
32993300

3300-
for i := 0; i<contextRaceIterations; i++ {
3301+
for i := rangecontextRaceIterations {
33013302
func() {
33023303
ctx, cancel := context.WithCancel(context.Background())
33033304
defer cancel()
@@ -3552,8 +3553,8 @@ func TestConnectionAttributes(t *testing.T) {
35523553
rowsMap[attrName] = attrValue
35533554
}
35543555

3555-
connAttrs := append(append([]string{}, defaultAttrs...), customAttrs...)
3556-
expectedAttrValues := append(append([]string{}, defaultAttrValues...), customAttrValues...)
3556+
connAttrs := slices.Concat(defaultAttrs, customAttrs)
3557+
expectedAttrValues := slices.Concat(defaultAttrValues, customAttrValues)
35573558
for i := range connAttrs {
35583559
if gotValue := rowsMap[connAttrs[i]]; gotValue != expectedAttrValues[i] {
35593560
dbt.Errorf("expected %q, got %q", expectedAttrValues[i], gotValue)
@@ -3637,7 +3638,7 @@ func TestIssue1567(t *testing.T) {
36373638
count = max
36383639
}
36393640

3640-
for i:=0; i<count; i++ {
3641+
for rangecount {
36413642
timeout := time.Duration(mrand.Int63n(int64(rtt)))
36423643
ctx, cancel := context.WithTimeout(context.Background(), timeout)
36433644
dbt.db.PingContext(ctx)

‎dsn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ func ParseDSN(dsn string) (cfg *Config, err error) {
414414
if dsn[j] == '@' {
415415
// username[:password]
416416
// Find the first ':' in dsn[:j]
417-
for k = 0; k < j; k++ {
417+
for k = 0; k < j; k++ {// We cannot use k = range j here, because we use dsn[:k] below
418418
if dsn[k] == ':' {
419419
cfg.Passwd = dsn[k+1 : j]
420420
break

‎infile.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ const defaultPacketSize = 16 * 1024 // 16KB is small enough for disk readahead a
9595

9696
func (mc *okHandler) handleInFileRequest(name string) (err error) {
9797
var rdr io.Reader
98-
packetSize := defaultPacketSize
99-
if mc.maxWriteSize < packetSize {
100-
packetSize = mc.maxWriteSize
101-
}
98+
packetSize := min(mc.maxWriteSize, defaultPacketSize)
10299

103100
if idx := strings.Index(name, "Reader::"); idx == 0 || (idx > 0 && name[idx-1] == '/') { // io.Reader
104101
// The server might return an an absolute path. See issue #355.

‎packets.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -984,10 +984,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
984984
mc := stmt.mc
985985

986986
// Determine threshold dynamically to avoid packet size shortage.
987-
longDataSize := mc.maxAllowedPacket / (stmt.paramCount + 1)
988-
if longDataSize < 64 {
989-
longDataSize = 64
990-
}
987+
longDataSize := max(mc.maxAllowedPacket/(stmt.paramCount+1), 64)
991988

992989
// Reset packet-sequence
993990
mc.resetSequence()

‎result.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
package mysql
1010

11+
import "slices"
12+
1113
import "database/sql/driver"
1214

1315
// Result exposes data not available through *connection.Result.
@@ -42,9 +44,9 @@ func (res *mysqlResult) RowsAffected() (int64, error) {
4244
}
4345

4446
func (res *mysqlResult) AllLastInsertIds() []int64 {
45-
return append([]int64{}, res.insertIds...) // defensive copy
47+
return slices.Clone(res.insertIds) // defensive copy
4648
}
4749

4850
func (res *mysqlResult) AllRowsAffected() []int64 {
49-
return append([]int64{}, res.affectedRows...) // defensive copy
51+
return slices.Clone(res.affectedRows) // defensive copy
5052
}

‎utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func parseDateTime(b []byte, loc *time.Location) (time.Time, error) {
182182

183183
func parseByteYear(b []byte) (int, error) {
184184
year, n := 0, 1000
185-
for i := 0; i<4; i++ {
185+
for i := range4 {
186186
v, err := bToi(b[i])
187187
if err != nil {
188188
return 0, err
@@ -207,7 +207,7 @@ func parseByte2Digits(b1, b2 byte) (int, error) {
207207

208208
func parseByteNanoSec(b []byte) (int, error) {
209209
ns, digit := 0, 100000 // max is 6-digits
210-
for i := 0; i<len(b); i++ {
210+
for i := rangeb {
211211
v, err := bToi(b[i])
212212
if err != nil {
213213
return 0, err
@@ -678,7 +678,7 @@ func escapeStringBackslash(buf []byte, v string) []byte {
678678
pos := len(buf)
679679
buf = reserveBuffer(buf, len(v)*2)
680680

681-
for i := 0; i<len(v); i++ {
681+
for i := rangelen(v) {
682682
c := v[i]
683683
switch c {
684684
case '\x00':
@@ -746,7 +746,7 @@ func escapeStringQuotes(buf []byte, v string) []byte {
746746
pos := len(buf)
747747
buf = reserveBuffer(buf, len(v)*2)
748748

749-
for i := 0; i<len(v); i++ {
749+
for i := rangelen(v) {
750750
c := v[i]
751751
if c == '\'' {
752752
buf[pos+1] = '\''

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /