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/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/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 }