From d9e59b684e4eff5ca94f2c56d4baa861554444ec Mon Sep 17 00:00:00 2001 From: Christopher Mejia <58187990+chrism1001@users.noreply.github.com> Date: Wed, 11 Sep 2024 16:53:37 -0400 Subject: [PATCH] Update part of codebase to use new for := range syntax (#16738) Signed-off-by: Christopher Mejia --- go/mysql/auth_server.go | 2 +- go/mysql/binlog/binlog_json.go | 8 ++++---- go/mysql/binlog/rbr.go | 6 +++--- go/mysql/binlog_event.go | 2 +- go/mysql/binlog_event_make_test.go | 10 +++++----- go/mysql/collations/charset/helpers.go | 2 +- go/mysql/collations/colldata/8bit.go | 4 ++-- .../colldata/uca_contraction_test.go | 6 +++--- go/mysql/collations/colldata/uca_test.go | 6 +++--- .../collations/internal/uca/iter_fast_900.go | 2 +- go/mysql/collations/internal/uca/layout.go | 8 ++++---- .../tools/makecolldata/codegen/tablegen.go | 6 +++--- .../vindex/unicode/norm/composition.go | 2 +- go/mysql/conn.go | 2 +- go/mysql/conn_test.go | 4 ++-- go/mysql/datetime/helpers.go | 8 ++++---- go/mysql/decimal/mysql_test.go | 20 +++++++++---------- go/mysql/endtoend/client_test.go | 2 +- go/mysql/endtoend/query_benchmark_test.go | 14 ++++++------- go/mysql/endtoend/query_test.go | 4 ++-- go/mysql/fastparse/atof.go | 2 +- go/mysql/icuregex/compiler.go | 6 +++--- go/mysql/icuregex/icu_test.go | 4 ++-- go/mysql/icuregex/internal/ubidi/ubidi.go | 2 +- go/mysql/icuregex/internal/uchar/uchar.go | 4 ++-- go/mysql/icuregex/internal/unames/loader.go | 2 +- go/mysql/icuregex/internal/unames/unames.go | 4 ++-- .../icuregex/internal/uprops/properties.go | 4 ++-- go/mysql/icuregex/internal/uset/close.go | 2 +- go/mysql/icuregex/internal/uset/pattern.go | 2 +- .../icuregex/internal/uset/unicode_set.go | 4 ++-- go/mysql/icuregex/matcher.go | 2 +- go/mysql/json/parser.go | 4 ++-- go/mysql/mysql_fuzzer.go | 4 ++-- go/mysql/query.go | 16 +++++++-------- go/mysql/replication/mysql56_gtid_set.go | 2 +- 36 files changed, 91 insertions(+), 91 deletions(-) diff --git a/go/mysql/auth_server.go b/go/mysql/auth_server.go index 64274ef3d66..59a5634bbc0 100644 --- a/go/mysql/auth_server.go +++ b/go/mysql/auth_server.go @@ -601,7 +601,7 @@ func newSalt() ([]byte, error) { } // Salt must be a legal UTF8 string. - for i := 0; i < len(salt); i++ { + for i := range len(salt) { salt[i] &= 0x7f if salt[i] == '\x00' || salt[i] == '$' { salt[i]++ diff --git a/go/mysql/binlog/binlog_json.go b/go/mysql/binlog/binlog_json.go index 2a0aba3163a..03bf604fb2d 100644 --- a/go/mysql/binlog/binlog_json.go +++ b/go/mysql/binlog/binlog_json.go @@ -224,7 +224,7 @@ var binaryIntSizes = map[jsonDataType]int{ func binparserInt(typ jsonDataType, data []byte, pos int) (*json.Value, error) { var val uint64 size := binaryIntSizes[typ] - for i := 0; i < size; i++ { + for i := range size { val = val + uint64(data[pos+i])<<(8*i) } var s string @@ -344,7 +344,7 @@ func binparserArray(typ jsonDataType, data []byte, pos int) (node *json.Value, e large := typ == jsonLargeArray elementCount, pos = readInt(data, pos, large) _, pos = readInt(data, pos, large) - for i := 0; i < elementCount; i++ { + for range elementCount { elem, pos, err = binparserElement(data, pos, large) if err != nil { return nil, err @@ -366,7 +366,7 @@ func binparserObject(typ jsonDataType, data []byte, pos int) (node *json.Value, _, pos = readInt(data, pos, large) keys := make([]string, elementCount) // stores all the keys in this object - for i := 0; i < elementCount; i++ { + for i := range elementCount { var keyOffset int var keyLength int keyOffset, pos = readInt(data, pos, large) @@ -384,7 +384,7 @@ func binparserObject(typ jsonDataType, data []byte, pos int) (node *json.Value, var elem *json.Value // get the value for each key - for i := 0; i < elementCount; i++ { + for i := range elementCount { elem, pos, err = binparserElement(data, pos, large) if err != nil { return nil, err diff --git a/go/mysql/binlog/rbr.go b/go/mysql/binlog/rbr.go index 23faf188ae9..8b95b0daee9 100644 --- a/go/mysql/binlog/rbr.go +++ b/go/mysql/binlog/rbr.go @@ -542,7 +542,7 @@ func CellValue(data []byte, pos int, typ byte, metadata uint16, field *querypb.F } // now the full digits, 32 bits each, 9 digits - for i := 0; i < intg0; i++ { + for range intg0 { val = binary.BigEndian.Uint32(d[pos : pos+4]) fmt.Fprintf(txt, "%09d", val) pos += 4 @@ -564,7 +564,7 @@ func CellValue(data []byte, pos int, typ byte, metadata uint16, field *querypb.F txt.WriteByte('.') // now the full fractional digits - for i := 0; i < frac0; i++ { + for range frac0 { val = binary.BigEndian.Uint32(d[pos : pos+4]) fmt.Fprintf(txt, "%09d", val) pos += 4 @@ -718,7 +718,7 @@ func CellValue(data []byte, pos int, typ byte, metadata uint16, field *querypb.F // numbers. l := int(metadata & 0xff) var val uint64 - for i := 0; i < l; i++ { + for i := range l { val += uint64(data[pos+i]) << (uint(i) * 8) } return sqltypes.MakeTrusted(querypb.Type_UINT64, diff --git a/go/mysql/binlog_event.go b/go/mysql/binlog_event.go index 5e5ce01eac3..27af9926c0c 100644 --- a/go/mysql/binlog_event.go +++ b/go/mysql/binlog_event.go @@ -328,7 +328,7 @@ func (b *Bitmap) Set(index int, value bool) { // hence the non-efficient logic. func (b *Bitmap) BitCount() int { sum := 0 - for i := 0; i < b.count; i++ { + for i := range b.count { if b.Bit(i) { sum++ } diff --git a/go/mysql/binlog_event_make_test.go b/go/mysql/binlog_event_make_test.go index 32401bfa401..dddca2e0265 100644 --- a/go/mysql/binlog_event_make_test.go +++ b/go/mysql/binlog_event_make_test.go @@ -254,7 +254,7 @@ func TestLargeTableMapEvent(t *testing.T) { types := make([]byte, 0, colLen) metadata := make([]uint16, 0, colLen) - for i := 0; i < colLen; i++ { + for range colLen { types = append(types, binlog.TypeLongLong) metadata = append(metadata, 0) } @@ -429,7 +429,7 @@ func TestLargeRowsEvent(t *testing.T) { types := make([]byte, 0, colLen) metadata := make([]uint16, 0, colLen) - for i := 0; i < colLen; i++ { + for range colLen { types = append(types, binlog.TypeLong) metadata = append(metadata, 0) } @@ -446,7 +446,7 @@ func TestLargeRowsEvent(t *testing.T) { identify := make([]byte, 0, colLen*4) data := make([]byte, 0, colLen*4) - for i := 0; i < colLen; i++ { + for range colLen { identify = append(identify, 0x10, 0x20, 0x30, 0x40) data = append(data, 0x10, 0x20, 0x30, 0x40) } @@ -467,7 +467,7 @@ func TestLargeRowsEvent(t *testing.T) { } // All rows are included, none are NULL. - for i := 0; i < colLen; i++ { + for i := range colLen { rows.IdentifyColumns.Set(i, true) rows.DataColumns.Set(i, true) } @@ -476,7 +476,7 @@ func TestLargeRowsEvent(t *testing.T) { // 1076895760 is 0x40302010. identifies, _ := rows.StringIdentifiesForTests(tm, 0) expected := make([]string, 0, colLen) - for i := 0; i < colLen; i++ { + for range colLen { expected = append(expected, "1076895760") } if !reflect.DeepEqual(identifies, expected) { diff --git a/go/mysql/collations/charset/helpers.go b/go/mysql/collations/charset/helpers.go index b66a6c77b87..62216394263 100644 --- a/go/mysql/collations/charset/helpers.go +++ b/go/mysql/collations/charset/helpers.go @@ -22,7 +22,7 @@ func Slice(charset Charset, input []byte, from, to int) []byte { } iter := input start := 0 - for i := 0; i < to; i++ { + for i := range to { r, size := charset.DecodeRune(iter) if r == RuneError && size < 2 { break diff --git a/go/mysql/collations/colldata/8bit.go b/go/mysql/collations/colldata/8bit.go index 67ae8541d56..c88e1ec3a2d 100644 --- a/go/mysql/collations/colldata/8bit.go +++ b/go/mysql/collations/colldata/8bit.go @@ -158,7 +158,7 @@ func (c *Collation_8bit_simple_ci) Collate(left, right []byte, rightIsPrefix boo sortOrder := c.sort cmpLen := min(len(left), len(right)) - for i := 0; i < cmpLen; i++ { + for i := range cmpLen { sortL, sortR := sortOrder[left[i]], sortOrder[right[i]] if sortL != sortR { return int(sortL) - int(sortR) @@ -174,7 +174,7 @@ func (c *Collation_8bit_simple_ci) TinyWeightString(src []byte) uint32 { var w32 [4]byte sortOrder := c.sort sortLen := min(4, len(src)) - for i := 0; i < sortLen; i++ { + for i := range sortLen { w32[i] = sortOrder[src[i]] } return binary.BigEndian.Uint32(w32[:4]) diff --git a/go/mysql/collations/colldata/uca_contraction_test.go b/go/mysql/collations/colldata/uca_contraction_test.go index a3511a07df6..3503b6e6ad8 100644 --- a/go/mysql/collations/colldata/uca_contraction_test.go +++ b/go/mysql/collations/colldata/uca_contraction_test.go @@ -129,7 +129,7 @@ func benchmarkFind(b *testing.B, input []byte, contract uca.Contractor) { b.ReportAllocs() b.ResetTimer() - for n := 0; n < b.N; n++ { + for range b.N { in := input for len(in) > 0 { cp, width := utf8.DecodeRune(in) @@ -144,7 +144,7 @@ func benchmarkFindJA(b *testing.B, input []byte, contract uca.Contractor) { b.ReportAllocs() b.ResetTimer() - for n := 0; n < b.N; n++ { + for range b.N { prev := rune(0) in := input for len(in) > 0 { @@ -166,7 +166,7 @@ func newStrgen() *strgen { } func (s *strgen) withASCII() *strgen { - for r := rune(0); r < utf8.RuneSelf; r++ { + for r := range rune(utf8.RuneSelf) { s.repertoire[r] = struct{}{} } return s diff --git a/go/mysql/collations/colldata/uca_test.go b/go/mysql/collations/colldata/uca_test.go index 5eb51fed67e..4be261edf9c 100644 --- a/go/mysql/collations/colldata/uca_test.go +++ b/go/mysql/collations/colldata/uca_test.go @@ -180,7 +180,7 @@ func TestIsPrefix(t *testing.T) { coll := testcollation(t, collName) input := []rune(strings.ToUpper(ExampleStringLong)) - for size := 0; size < len(input); size++ { + for size := range len(input) { left := ExampleStringLong right := string(input[:size]) @@ -777,7 +777,7 @@ func BenchmarkAllUCAWeightStrings(b *testing.B) { b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { _ = collation.WeightString(buf, input, 0) } }) @@ -1058,7 +1058,7 @@ func BenchmarkUCA900Collation(b *testing.B) { str2 := []byte(strings.ToUpper(content)) for _, collation := range Collations { b.Run(fmt.Sprintf("%s/%d/%s", teststr.Name, length, collation.Name()), func(b *testing.B) { - for i := 0; i < b.N; i++ { + for range b.N { _ = collation.Collate(str1, str2, false) } }) diff --git a/go/mysql/collations/internal/uca/iter_fast_900.go b/go/mysql/collations/internal/uca/iter_fast_900.go index cbe32cfdb70..42e32042133 100644 --- a/go/mysql/collations/internal/uca/iter_fast_900.go +++ b/go/mysql/collations/internal/uca/iter_fast_900.go @@ -301,7 +301,7 @@ func (it *FastIterator900) NextWeightBlock64(dstbytes []byte) int { // Slow path: just loop up to 8 times to fill the buffer and bail // early if we exhaust the iterator. - for i := 0; i < 8; i++ { + for i := range 8 { w, ok := it.Next() if !ok { return i * 2 diff --git a/go/mysql/collations/internal/uca/layout.go b/go/mysql/collations/internal/uca/layout.go index 35a2749eb21..e13fcb282b3 100644 --- a/go/mysql/collations/internal/uca/layout.go +++ b/go/mysql/collations/internal/uca/layout.go @@ -71,7 +71,7 @@ func equalWeights900(table Weights, levels int, A, B rune) bool { cA := int((*pageA)[offsetA]) cB := int((*pageB)[offsetB]) - for l := 0; l < levels; l++ { + for l := range levels { wA, wB := l*256, l*256 wA1, wB1 := wA+(cA*256*3), wB+(cB*256*3) @@ -118,7 +118,7 @@ func (Layout_uca900) DebugWeights(table Weights, codepoint rune) (result []uint1 } ceCount := int((*page)[offset]) - for ce := 0; ce < ceCount; ce++ { + for ce := range ceCount { result = append(result, (*page)[256+(ce*3+0)*256+offset], (*page)[256+(ce*3+1)*256+offset], @@ -264,8 +264,8 @@ func (Layout_uca_legacy) allocPage(original *[]uint16, patches []Patch) []uint16 } newPage := make([]uint16, minLenForPage) - for i := 0; i < CodepointsPerPage; i++ { - for j := 0; j < originalStride; j++ { + for i := range CodepointsPerPage { + for range originalStride { newPage[1+i*newStride] = (*original)[1+i*originalStride] } } diff --git a/go/mysql/collations/tools/makecolldata/codegen/tablegen.go b/go/mysql/collations/tools/makecolldata/codegen/tablegen.go index e1549c23bff..479e876f1f3 100644 --- a/go/mysql/collations/tools/makecolldata/codegen/tablegen.go +++ b/go/mysql/collations/tools/makecolldata/codegen/tablegen.go @@ -151,7 +151,7 @@ func (p *page) weights900Fast(level int) (w []uint32) { if p.entryCount == 0 { return nil } - for i := 0; i < 128; i++ { + for i := range 128 { entry := &p.entries[i] if len(entry.weights) > 3 { panic("trying to dump fast weights for codepoint with >3 weights") @@ -165,7 +165,7 @@ func (p *page) weights900Fast(level int) (w []uint32) { } w = append(w, weight) } - for i := 0; i < 128; i++ { + for range 128 { w = append(w, 0x0) } return @@ -179,7 +179,7 @@ func (p *page) weights900() (w []uint16) { for _, entry := range p.entries { w = append(w, uint16(len(entry.weights)/3)) } - for level := 0; level < maxCollations; level++ { + for level := range maxCollations { for _, entry := range p.entries { var weight uint16 if level < len(entry.weights) { diff --git a/go/mysql/collations/vindex/unicode/norm/composition.go b/go/mysql/collations/vindex/unicode/norm/composition.go index 0e1bcb94128..db97e1a8453 100644 --- a/go/mysql/collations/vindex/unicode/norm/composition.go +++ b/go/mysql/collations/vindex/unicode/norm/composition.go @@ -136,7 +136,7 @@ func (rb *reorderBuffer) doFlush() bool { // appendFlush appends the normalized segment to rb.out. func appendFlush(rb *reorderBuffer) bool { - for i := 0; i < rb.nrune; i++ { + for i := range rb.nrune { start := rb.rune[i].pos end := start + rb.rune[i].size rb.out = append(rb.out, rb.byte[start:end]...) diff --git a/go/mysql/conn.go b/go/mysql/conn.go index 56c2abff06e..d4f870e660f 100644 --- a/go/mysql/conn.go +++ b/go/mysql/conn.go @@ -1249,7 +1249,7 @@ func (c *Conn) handleComPrepare(handler Handler, data []byte) (kontinue bool) { } bindVars := make(map[string]*querypb.BindVariable, paramsCount) - for i := uint16(0); i < paramsCount; i++ { + for i := range uint16(paramsCount) { parameterID := fmt.Sprintf("v%d", i+1) bindVars[parameterID] = &querypb.BindVariable{} } diff --git a/go/mysql/conn_test.go b/go/mysql/conn_test.go index 786f4e4a19b..088e487e961 100644 --- a/go/mysql/conn_test.go +++ b/go/mysql/conn_test.go @@ -744,7 +744,7 @@ func TestEOFOrLengthEncodedIntFuzz(t *testing.T) { cConn.Close() }() - for i := 0; i < 100; i++ { + for range 100 { bytes := make([]byte, rand.IntN(16)+1) _, err := crypto_rand.Read(bytes) require.NoError(t, err, "error doing rand.Read") @@ -1001,7 +1001,7 @@ func TestPrepareAndExecute(t *testing.T) { // and check that the handler received the correct input ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) defer cancel() - for i := 0; i < 100; i++ { + for i := range 100 { startGoRoutine(ctx, t, fmt.Sprintf("%d:%s", i, randSeq(i))) } diff --git a/go/mysql/datetime/helpers.go b/go/mysql/datetime/helpers.go index 68466e320e2..fc25a6cba48 100644 --- a/go/mysql/datetime/helpers.go +++ b/go/mysql/datetime/helpers.go @@ -76,7 +76,7 @@ func appendInt(b []byte, x int, width int) []byte { // match reports whether s1 and s2 match ignoring case. // It is assumed s1 and s2 are the same length. func match(s1, s2 string) bool { - for i := 0; i < len(s1); i++ { + for i := range len(s1) { c1 := s1[i] c2 := s2[i] if c1 != c2 { @@ -153,7 +153,7 @@ func isDigit[bytes []byte | string](s bytes, i int) bool { func isNumber[bytes []byte | string](s bytes) (int, bool) { var dot bool pos := -1 - for i := 0; i < len(s); i++ { + for i := range len(s) { if !isDigit(s, i) { if dot { return i, true @@ -189,7 +189,7 @@ func getnum(s string, fixed bool) (int, string, bool) { func getnuml(s string, l int) (int, string, bool) { var res int - for i := 0; i < l; i++ { + for i := range l { if !isDigit(s, i) { return 0, s, false } @@ -273,7 +273,7 @@ func parseNanoseconds[bytes []byte | string](value bytes, nbytes int) (ns int, l // We need nanoseconds, which means scaling by the number // of missing digits in the format, maximum length 10. scaleDigits := 10 - nbytes - for i := 0; i < scaleDigits; i++ { + for range scaleDigits { ns *= 10 } diff --git a/go/mysql/decimal/mysql_test.go b/go/mysql/decimal/mysql_test.go index d1b0c52169b..602e4b41eef 100644 --- a/go/mysql/decimal/mysql_test.go +++ b/go/mysql/decimal/mysql_test.go @@ -234,10 +234,10 @@ func TestLargeDecimals(t *testing.T) { } func TestVeryLargeDecimals(t *testing.T) { - for i := 0; i <= 65; i++ { + for i := range 66 { integral := bytes.Repeat([]byte{'9'}, i) integral = append(integral, '.') - for j := 0; j <= 65; j++ { + for j := range 66 { decimal := append(integral, bytes.Repeat([]byte{'9'}, j)...) _, err := NewFromMySQL(decimal) if err != nil { @@ -308,7 +308,7 @@ var decimals = []string{ func BenchmarkDecimalParsing(b *testing.B) { b.Run("Naive", func(b *testing.B) { b.ReportAllocs() - for n := 0; n < b.N; n++ { + for range b.N { for _, dec := range decimals { _, _ = NewFromString(dec) } @@ -322,7 +322,7 @@ func BenchmarkDecimalParsing(b *testing.B) { b.Run("MySQL", func(b *testing.B) { b.ReportAllocs() - for n := 0; n < b.N; n++ { + for range b.N { for _, dec := range decimalBytes { _, _ = NewFromMySQL(dec) } @@ -365,7 +365,7 @@ func TestRoundtripStress(t *testing.T) { count = 100 } - for n := 0; n < count; n++ { + for range count { fb := strconv.AppendFloat(nil, rand.NormFloat64(), 'f', -1, 64) d, err := NewFromMySQL(fb) if err != nil { @@ -381,13 +381,13 @@ func TestRoundtripStress(t *testing.T) { func BenchmarkFormatting(b *testing.B) { const Count = 10000 var parsed = make([]Decimal, 0, Count) - for i := 0; i < Count; i++ { + for range Count { parsed = append(parsed, NewFromFloat(rand.NormFloat64())) } b.Run("StringFixed(8)", func(b *testing.B) { b.ReportAllocs() - for n := 0; n < b.N; n++ { + for range b.N { for _, dec := range parsed { _ = dec.StringFixed(8) } @@ -396,7 +396,7 @@ func BenchmarkFormatting(b *testing.B) { b.Run("formatwithPrecision(8)", func(b *testing.B) { b.ReportAllocs() - for n := 0; n < b.N; n++ { + for range b.N { for _, dec := range parsed { _ = dec.formatFast(8, true, false) } @@ -405,7 +405,7 @@ func BenchmarkFormatting(b *testing.B) { b.Run("formatFast", func(b *testing.B) { b.ReportAllocs() - for n := 0; n < b.N; n++ { + for range b.N { for _, dec := range parsed { _ = dec.formatFast(0, false, false) } @@ -414,7 +414,7 @@ func BenchmarkFormatting(b *testing.B) { b.Run("formatSlow", func(b *testing.B) { b.ReportAllocs() - for n := 0; n < b.N; n++ { + for range b.N { for _, dec := range parsed { _ = dec.formatSlow(false) } diff --git a/go/mysql/endtoend/client_test.go b/go/mysql/endtoend/client_test.go index ce01c57369d..7799a322429 100644 --- a/go/mysql/endtoend/client_test.go +++ b/go/mysql/endtoend/client_test.go @@ -204,7 +204,7 @@ func doTestMultiResult(t *testing.T, disableClientDeprecateEOF bool) { require.NoError(t, err) assert.Zero(t, result.RowsAffected, "create table RowsAffected ") - for i := 0; i < 255; i++ { + for i := range 255 { result, err := conn.ExecuteFetch(fmt.Sprintf("insert into a(id, name) values(%v, 'nice name %v')", 1000+i, i), 1000, true) require.NoError(t, err) assert.EqualValues(t, 1, result.RowsAffected, "insert into returned RowsAffected") diff --git a/go/mysql/endtoend/query_benchmark_test.go b/go/mysql/endtoend/query_benchmark_test.go index 7552e470b53..9bfd866a551 100644 --- a/go/mysql/endtoend/query_benchmark_test.go +++ b/go/mysql/endtoend/query_benchmark_test.go @@ -95,7 +95,7 @@ func benchmarkInserts(b *testing.B, params *mysql.ConnParams) { b.ResetTimer() // Do the insert. - for i := 0; i < b.N; i++ { + for i := range b.N { _, err := conn.ExecuteFetch(fmt.Sprintf("insert into a(id, name) values(%v, 'nice name %v')", i, i), 0, false) if err != nil { b.Fatalf("ExecuteFetch(%v) failed: %v", i, err) @@ -106,7 +106,7 @@ func benchmarkInserts(b *testing.B, params *mysql.ConnParams) { func benchmarkParallelReads(b *testing.B, params *mysql.ConnParams, parallelCount int) { ctx := context.Background() wg := sync.WaitGroup{} - for i := 0; i < parallelCount; i++ { + for i := range parallelCount { wg.Add(1) go func(i int) { defer wg.Done() @@ -116,7 +116,7 @@ func benchmarkParallelReads(b *testing.B, params *mysql.ConnParams, parallelCoun b.Error(err) } - for j := 0; j < b.N; j++ { + for j := range b.N { if _, err := conn.ExecuteFetch("select * from a", 20000, true); err != nil { b.Errorf("ExecuteFetch(%v, %v) failed: %v", i, j, err) } @@ -144,7 +144,7 @@ func BenchmarkSetVarsWithQueryHints(b *testing.B) { for _, sleepDuration := range []time.Duration{0, 1 * time.Millisecond} { b.Run(fmt.Sprintf("Sleep %d ms", sleepDuration/time.Millisecond), func(b *testing.B) { - for i := 0; i < b.N; i++ { + for i := range b.N { _, err := conn.ExecuteFetch(fmt.Sprintf("insert /*+ SET_VAR(sql_mode = ' ') SET_VAR(sql_safe_updates = 0) */ into t(id) values (%d)", i), 1, false) if err != nil { b.Fatal(err) @@ -194,7 +194,7 @@ func BenchmarkSetVarsMultipleSets(b *testing.B) { for _, sleepDuration := range []time.Duration{0, 1 * time.Millisecond} { b.Run(fmt.Sprintf("Sleep %d ms", sleepDuration/time.Millisecond), func(b *testing.B) { - for i := 0; i < b.N; i++ { + for i := range b.N { setFunc() _, err = conn.ExecuteFetch(fmt.Sprintf("insert into t(id) values (%d)", i), 1, false) @@ -242,7 +242,7 @@ func BenchmarkSetVarsMultipleSetsInSameStmt(b *testing.B) { for _, sleepDuration := range []time.Duration{0, 1 * time.Millisecond} { b.Run(fmt.Sprintf("Sleep %d ms", sleepDuration/time.Millisecond), func(b *testing.B) { - for i := 0; i < b.N; i++ { + for i := range b.N { _, _, err := conn.ExecuteFetchMulti(fmt.Sprintf("set sql_mode = '', sql_safe_updates = 0 ; insert into t(id) values (%d)", i), 1, false) if err != nil { b.Fatal(err) @@ -304,7 +304,7 @@ func BenchmarkSetVarsSingleSet(b *testing.B) { for _, sleepDuration := range []time.Duration{0, 1 * time.Millisecond} { b.Run(fmt.Sprintf("Sleep %d ms", sleepDuration/time.Millisecond), func(b *testing.B) { - for i := 0; i < b.N; i++ { + for i := range b.N { _, err = conn.ExecuteFetch(fmt.Sprintf("insert into t(id) values (%d)", i), 1, false) if err != nil { b.Fatal(err) diff --git a/go/mysql/endtoend/query_test.go b/go/mysql/endtoend/query_test.go index 3436d045071..5d7511b4834 100644 --- a/go/mysql/endtoend/query_test.go +++ b/go/mysql/endtoend/query_test.go @@ -121,7 +121,7 @@ func TestQueries(t *testing.T) { } // Insert a few rows. - for i := 0; i < 100; i++ { + for i := range 100 { result, err := conn.ExecuteFetch(fmt.Sprintf("insert into a(id, name) values(%v, 'nice name %v')", 1000+i, i), 1000, true) require.NoError(t, err, "ExecuteFetch(%v) failed: %v", i, err) assert.Equal(t, uint64(1), result.RowsAffected, "insert into returned RowsAffected %v, was expecting 1", result.RowsAffected) @@ -156,7 +156,7 @@ func TestLargeQueries(t *testing.T) { return string(b) } - for i := 0; i < 2; i++ { + for i := range 2 { for j := -2; j < 2; j++ { expectedString := randString((i+1)*mysql.MaxPacketSize + j) diff --git a/go/mysql/fastparse/atof.go b/go/mysql/fastparse/atof.go index 4193031c987..695d9e32edb 100644 --- a/go/mysql/fastparse/atof.go +++ b/go/mysql/fastparse/atof.go @@ -64,7 +64,7 @@ func commonPrefixLenIgnoreCase(s, prefix string) int { if n > len(s) { n = len(s) } - for i := 0; i < n; i++ { + for i := range n { c := s[i] if 'A' <= c && c <= 'Z' { c += 'a' - 'A' diff --git a/go/mysql/icuregex/compiler.go b/go/mysql/icuregex/compiler.go index 6aa92e268bb..83962ef73b2 100644 --- a/go/mysql/icuregex/compiler.go +++ b/go/mysql/icuregex/compiler.go @@ -240,7 +240,7 @@ func (c *compiler) nextChar(ch *reChar) { // ch.char = 0 c.nextCharLL() // Consume the initial 0. - for index := 0; index < 3; index++ { + for index := range 3 { ch2 := c.peekCharLL() if ch2 < chDigit0 || ch2 > chDigit7 { if index == 0 { @@ -1740,7 +1740,7 @@ func (c *compiler) stripNOPs() { // Make a first pass over the code, computing the amount that things // will be offset at each location in the original code. var loc, d int - for loc = 0; loc < end; loc++ { + for loc = range end { deltas = append(deltas, d) op := c.out.compiledPat[loc] if op.typ() == urxNop { @@ -1753,7 +1753,7 @@ func (c *compiler) stripNOPs() { // are being moved. The array of offsets from the first step is used // to compute the new operand values. var src, dst int - for src = 0; src < end; src++ { + for src = range end { op := c.out.compiledPat[src] opType := op.typ() diff --git a/go/mysql/icuregex/icu_test.go b/go/mysql/icuregex/icu_test.go index 9e9be505df7..4336608f0d8 100644 --- a/go/mysql/icuregex/icu_test.go +++ b/go/mysql/icuregex/icu_test.go @@ -267,7 +267,7 @@ func (tp *TestPattern) Test(t testing.TB) bool { findCount = 1 } - for i := 0; i < findCount; i++ { + for range findCount { isMatch, err = func() (bool, error) { defer func() { if r := recover(); r != nil { @@ -299,7 +299,7 @@ func (tp *TestPattern) Test(t testing.TB) bool { return true } - for i := 0; i < matcher.GroupCount(); i++ { + for i := range matcher.GroupCount() { expectedStart := -1 expectedEnd := -1 diff --git a/go/mysql/icuregex/internal/ubidi/ubidi.go b/go/mysql/icuregex/internal/ubidi/ubidi.go index 79482dfbc8d..1aaa8a0a791 100644 --- a/go/mysql/icuregex/internal/ubidi/ubidi.go +++ b/go/mysql/icuregex/internal/ubidi/ubidi.go @@ -297,7 +297,7 @@ func AddPropertyStarts(sa propertySet) { mrs := mirrors() /* add the code points from the bidi mirroring table */ length := idxs[ixMirrorLength] - for i := int32(0); i < length; i++ { + for i := range int32(length) { c := mirrorCodePoint(rune(mrs[i])) sa.AddRuneRange(c, c+1) } diff --git a/go/mysql/icuregex/internal/uchar/uchar.go b/go/mysql/icuregex/internal/uchar/uchar.go index e93b51d9bb4..1fbc874665b 100644 --- a/go/mysql/icuregex/internal/uchar/uchar.go +++ b/go/mysql/icuregex/internal/uchar/uchar.go @@ -203,7 +203,7 @@ func parseInt(str string) (string, uint8) { start := 0 end := 0 whitespace: - for i := 0; i < len(str); i++ { + for i := range len(str) { switch str[i] { case ' ', '\f', '\n', '\r', '\t', '\v': start++ @@ -214,7 +214,7 @@ whitespace: } str = str[start:] - for i := 0; i < len(str); i++ { + for i := range len(str) { if str[i] < '0' || str[i] > '9' { end = i break diff --git a/go/mysql/icuregex/internal/unames/loader.go b/go/mysql/icuregex/internal/unames/loader.go index 296670b1c66..60969f6350b 100644 --- a/go/mysql/icuregex/internal/unames/loader.go +++ b/go/mysql/icuregex/internal/unames/loader.go @@ -69,7 +69,7 @@ func loadCharNames() { algCount := b.Uint32() charNames.algNames = make([]algorithmicRange, 0, algCount) - for i := uint32(0); i < algCount; i++ { + for range uint32(algCount) { ar := algorithmicRange{ start: b.Uint32(), end: b.Uint32(), diff --git a/go/mysql/icuregex/internal/unames/unames.go b/go/mysql/icuregex/internal/unames/unames.go index 66e8ba15615..bdd30495458 100644 --- a/go/mysql/icuregex/internal/unames/unames.go +++ b/go/mysql/icuregex/internal/unames/unames.go @@ -130,7 +130,7 @@ func (ar *algorithmicRange) findAlgName(otherName string) rune { } t := otherName - for i = 0; i < len(factors); i++ { + for i = range len(factors) { s = elements[i] for s[0] != 0 && len(t) > 0 { @@ -153,7 +153,7 @@ func (ar *algorithmicRange) findAlgName(otherName string) rune { func (ar *algorithmicRange) writeFactorSuffix0(factors []uint16, s []uint8, buf *strings.Builder, elements, elementBases *[8][]byte) { /* write each element */ - for i := 0; i < len(factors); i++ { + for i := range len(factors) { (*elements)[i] = s (*elementBases)[i] = s diff --git a/go/mysql/icuregex/internal/uprops/properties.go b/go/mysql/icuregex/internal/uprops/properties.go index 954fc920f6c..9e9bfb2761d 100644 --- a/go/mysql/icuregex/internal/uprops/properties.go +++ b/go/mysql/icuregex/internal/uprops/properties.go @@ -114,7 +114,7 @@ func getInclusionsForBinaryProperty(prop Property) (*uset.UnicodeSet, error) { numRanges := incl.RangeCount() startHasProperty := rune(-1) - for i := 0; i < numRanges; i++ { + for i := range numRanges { rangeEnd := incl.RangeEnd(i) for c := incl.RangeStart(i); c <= rangeEnd; c++ { if HasBinaryProperty(c, prop) { @@ -152,7 +152,7 @@ func getInclusionsForIntProperty(prop Property) (*uset.UnicodeSet, error) { numRanges := incl.RangeCount() prevValue := int32(0) - for i := 0; i < numRanges; i++ { + for i := range numRanges { rangeEnd := incl.RangeEnd(i) for c := incl.RangeStart(i); c <= rangeEnd; c++ { value := getIntPropertyValue(c, prop) diff --git a/go/mysql/icuregex/internal/uset/close.go b/go/mysql/icuregex/internal/uset/close.go index bd3f9f0f7e3..56438804bf3 100644 --- a/go/mysql/icuregex/internal/uset/close.go +++ b/go/mysql/icuregex/internal/uset/close.go @@ -82,7 +82,7 @@ func (u *UnicodeSet) CloseOver(attribute USet) { foldSet := u.Clone() n := u.RangeCount() - for i := 0; i < n; i++ { + for i := range n { start := u.RangeStart(i) end := u.RangeEnd(i) diff --git a/go/mysql/icuregex/internal/uset/pattern.go b/go/mysql/icuregex/internal/uset/pattern.go index 20b44da9c6d..af836941647 100644 --- a/go/mysql/icuregex/internal/uset/pattern.go +++ b/go/mysql/icuregex/internal/uset/pattern.go @@ -69,7 +69,7 @@ func (u *UnicodeSet) ToPattern(w *strings.Builder, escapeUnprintable bool) { } } else { // Default; emit the ranges as pairs - for i := 0; i < count; i++ { + for i := range count { start := u.RangeStart(i) end := u.RangeEnd(i) u.appendToPattern(w, start, escapeUnprintable) diff --git a/go/mysql/icuregex/internal/uset/unicode_set.go b/go/mysql/icuregex/internal/uset/unicode_set.go index d85bab47532..27cfb92d916 100644 --- a/go/mysql/icuregex/internal/uset/unicode_set.go +++ b/go/mysql/icuregex/internal/uset/unicode_set.go @@ -471,7 +471,7 @@ func (u *UnicodeSet) Clear() { func (u *UnicodeSet) Len() (n int) { count := u.RangeCount() - for i := 0; i < count; i++ { + for i := range count { n += int(u.RangeEnd(i)) - int(u.RangeStart(i)) + 1 } return @@ -616,7 +616,7 @@ func (u *UnicodeSet) ApplyFilter(inclusions *UnicodeSet, filter Filter) { startHasProperty := rune(-1) limitRange := inclusions.RangeCount() - for j := 0; j < limitRange; j++ { + for j := range limitRange { // get current range start := inclusions.RangeStart(j) end := inclusions.RangeEnd(j) diff --git a/go/mysql/icuregex/matcher.go b/go/mysql/icuregex/matcher.go index 1b5495f495f..aa0a78385e4 100644 --- a/go/mysql/icuregex/matcher.go +++ b/go/mysql/icuregex/matcher.go @@ -128,7 +128,7 @@ func (m *Matcher) MatchAt(startIdx int, toEnd bool) error { fp := m.resetStack() *fp.inputIdx() = startIdx *fp.patIdx() = 0 - for i := 0; i < len(m.data); i++ { + for i := range len(m.data) { m.data[i] = 0 } diff --git a/go/mysql/json/parser.go b/go/mysql/json/parser.go index b7a87c25756..02225c7db24 100644 --- a/go/mysql/json/parser.go +++ b/go/mysql/json/parser.go @@ -328,7 +328,7 @@ func hasSpecialChars(s string) bool { if strings.IndexByte(s, '"') >= 0 || strings.IndexByte(s, '\\') >= 0 { return true } - for i := 0; i < len(s); i++ { + for i := range len(s) { if s[i] < 0x20 { return true } @@ -420,7 +420,7 @@ func unescapeStringBestEffort(s string) string { // parseRawKey is similar to parseRawString, but is optimized // for small-sized keys without escape sequences. func parseRawKey(s string) (string, string, bool, error) { - for i := 0; i < len(s); i++ { + for i := range len(s) { if s[i] == '"' { // Fast path. return s[:i], s[i+1:], false, nil diff --git a/go/mysql/mysql_fuzzer.go b/go/mysql/mysql_fuzzer.go index 7370ad8a479..3ec302151f2 100644 --- a/go/mysql/mysql_fuzzer.go +++ b/go/mysql/mysql_fuzzer.go @@ -310,7 +310,7 @@ func FuzzTLSServer(data []byte) int { totalQueries := 20 var queries [][]byte c := gofuzzheaders.NewConsumer(data) - for i := 0; i < totalQueries; i++ { + for i := range totalQueries { query, err := c.GetBytes() if err != nil { return -1 @@ -377,7 +377,7 @@ func FuzzTLSServer(data []byte) int { return -1 } - for i := 0; i < len(queries); i++ { + for i := range len(queries) { conn.writeFuzzedPacket(queries[i]) } return 1 diff --git a/go/mysql/query.go b/go/mysql/query.go index 9126a85b2c5..46060a39c94 100644 --- a/go/mysql/query.go +++ b/go/mysql/query.go @@ -274,7 +274,7 @@ func (c *Conn) parseRow(data []byte, fields []*querypb.Field, reader func([]byte result = make([]sqltypes.Value, 0, colNumber) } pos := 0 - for i := 0; i < colNumber; i++ { + for i := range colNumber { if data[pos] == NullValue { result = append(result, sqltypes.Value{}) pos++ @@ -417,7 +417,7 @@ func (c *Conn) ReadQueryResult(maxrows int, wantfields bool) (*sqltypes.Result, // Read column headers. One packet per column. // Build the fields. - for i := 0; i < colNumber; i++ { + for i := range colNumber { result.Fields[i] = &fields[i] if wantfields { @@ -627,7 +627,7 @@ func (c *Conn) parseComStmtExecute(prepareData map[uint32]*PrepareData, data []b newParamsBoundFlag, pos, ok := readByte(payload, pos) if ok && newParamsBoundFlag == 0x01 { var mysqlType, flags byte - for i := uint16(0); i < prepare.ParamsCount; i++ { + for i := range uint16(prepare.ParamsCount) { mysqlType, pos, ok = readByte(payload, pos) if !ok { return stmtID, 0, sqlerror.NewSQLError(sqlerror.CRMalformedPacket, sqlerror.SSUnknownSQLState, "reading parameter type failed") @@ -648,7 +648,7 @@ func (c *Conn) parseComStmtExecute(prepareData map[uint32]*PrepareData, data []b } } - for i := 0; i < len(prepare.ParamsType); i++ { + for i := range len(prepare.ParamsType) { var val sqltypes.Value parameterID := fmt.Sprintf("v%d", i+1) if v, ok := prepare.BindVars[parameterID]; ok { @@ -1114,7 +1114,7 @@ func (c *Conn) writePrepare(fld []*querypb.Field, prepare *PrepareData) error { } if paramsCount > 0 { - for i := uint16(0); i < paramsCount; i++ { + for range uint16(paramsCount) { if err := c.writeColumnDefinition(&querypb.Field{ Name: "?", Type: sqltypes.VarBinary, @@ -1174,7 +1174,7 @@ func (c *Conn) writeBinaryRow(fields []*querypb.Field, row []sqltypes.Value) err pos = writeByte(data, pos, 0x00) - for i := 0; i < nullBitMapLen; i++ { + for range nullBitMapLen { pos = writeByte(data, pos, 0x00) } @@ -1315,7 +1315,7 @@ func val2MySQL(v sqltypes.Value) ([]byte, error) { } val := make([]byte, 6) count := copy(val, v.Raw()[20:]) - for i := 0; i < (6 - count); i++ { + for i := range 6 - count { val[count+i] = 0x30 } microSecond, err := strconv.ParseUint(string(val), 10, 32) @@ -1444,7 +1444,7 @@ func val2MySQL(v sqltypes.Value) ([]byte, error) { val := make([]byte, 6) count := copy(val, microSecond) - for i := 0; i < (6 - count); i++ { + for i := range 6 - count { val[count+i] = 0x30 } microSeconds, err := strconv.ParseUint(string(val), 10, 32) diff --git a/go/mysql/replication/mysql56_gtid_set.go b/go/mysql/replication/mysql56_gtid_set.go index 1d46176b19a..348af5b5274 100644 --- a/go/mysql/replication/mysql56_gtid_set.go +++ b/go/mysql/replication/mysql56_gtid_set.go @@ -619,7 +619,7 @@ func NewMysql56GTIDSetFromSIDBlock(data []byte) (Mysql56GTIDSet, error) { if err := binary.Read(buf, binary.LittleEndian, &nSIDs); err != nil { return nil, vterrors.Wrapf(err, "cannot read nSIDs") } - for i := uint64(0); i < nSIDs; i++ { + for i := range uint64(nSIDs) { var sid SID if c, err := buf.Read(sid[:]); err != nil || c != 16 { return nil, vterrors.Errorf(vtrpc.Code_INTERNAL, "cannot read SID %v: %v %v", i, err, c)