Skip to content

Commit

Permalink
for loop changes for files in: go/mysql/icuregex, go/mysql/binlog, go…
Browse files Browse the repository at this point in the history
…/mysql/decimal, go/mysql/fastparse

Signed-off-by: Christopher Mejia <[email protected]>
  • Loading branch information
chrism1001 committed Sep 10, 2024
1 parent a513601 commit 13b2a1c
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 36 deletions.
8 changes: 4 additions & 4 deletions go/mysql/binlog/binlog_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions go/mysql/binlog/rbr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions go/mysql/decimal/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/fastparse/atof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions go/mysql/icuregex/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions go/mysql/icuregex/icu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion go/mysql/icuregex/internal/ubidi/ubidi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions go/mysql/icuregex/internal/uchar/uchar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/icuregex/internal/unames/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions go/mysql/icuregex/internal/unames/unames.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions go/mysql/icuregex/internal/uprops/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/icuregex/internal/uset/close.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion go/mysql/icuregex/internal/uset/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions go/mysql/icuregex/internal/uset/unicode_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/icuregex/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 13b2a1c

Please sign in to comment.