Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
Godeps/_workspace/pkg
Godeps/_workspace/bin
_test
java/*/target
java/*/bin
php/vendor
releases
/dist/
/vthook/
Expand Down
8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ __debug_bin
# generated protobuf files
/go/vt/.proto.tmp

# Godeps files
/Godeps/_workspace/pkg
/Godeps/_workspace/bin

# Eclipse Java CheckStyle plugin configuration.
/java/*/.checkstyle
# java target files
Expand All @@ -52,10 +48,6 @@ __debug_bin
/java/pom.xml.versionsBackup
/java/*/pom.xml.versionsBackup

# php downloaded dependencies
/php/composer.phar
/php/vendor

report*.xml

# vitess.io preview site
Expand Down
Empty file removed .gitmodules
Empty file.
9 changes: 9 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ linters:
- nolintlint
- nosprintfhostport
- perfsprint
- prealloc
- sqlclosecheck
- staticcheck
- whitespace
Expand Down Expand Up @@ -144,6 +145,7 @@ linters:
path: ^go/mysql/
- linters:
- errcheck
- prealloc
path: ^go/pools/.*_test.go
- linters:
- errcheck
Expand All @@ -157,6 +159,7 @@ linters:
- linters:
- errcheck
- nosprintfhostport
- prealloc
- sqlclosecheck
path: ^go/test/
- linters:
Expand All @@ -179,9 +182,11 @@ linters:
path: ^go/vt/sqlparser/goyacc
- linters:
- errcheck
- prealloc
path: ^go/vt/throttler/.*_test.go
- linters:
- errcheck
- prealloc
path: ^go/vt/topo/.*/*._test.go
- linters:
- errcheck
Expand All @@ -197,12 +202,14 @@ linters:
path: ^go/vt/vtctl/grpcvtctlserver/
- linters:
- errcheck
- prealloc
path: ^go/vt/vtctld/(schema|.*_test).go
- linters:
- errcheck
path: ^go/vt/vtexplain/
- linters:
- errcheck
- prealloc
path: ^go/vt/vtgate/.*_test.go
- linters:
- errcheck
Expand All @@ -215,9 +222,11 @@ linters:
path: ^go/vt/vttablet/tabletmanager/vreplication
- linters:
- errcheck
- prealloc
path: ^go/vt/vttablet/(.*endtoend.*|.*_test.go)
- linters:
- errcheck
- prealloc
path: ^go/vt/vttest
- linters:
- errcheck
Expand Down
2 changes: 1 addition & 1 deletion go/cache/theine/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestList(t *testing.T) {
entry := l.PopTail()
require.Nil(t, entry)

var entries []*Entry[StringKey, string]
entries := make([]*Entry[StringKey, string], 0, 5)
for i := range 5 {
new := NewEntry(StringKey(strconv.Itoa(i)), "", 1)
evicted := l.PushFront(new)
Expand Down
4 changes: 2 additions & 2 deletions go/cache/theine/tlfu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestTlfu(t *testing.T) {
require.Equal(t, 0, tlfu.slru.probation.len)
require.Equal(t, 0, tlfu.slru.protected.len)

var entries []*Entry[StringKey, string]
entries := make([]*Entry[StringKey, string], 0, 200)
for i := range 200 {
e := NewEntry(StringKey(strconv.Itoa(i)), "", 1)
evicted := tlfu.Set(e)
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestTlfu(t *testing.T) {
require.Equal(t, StringKey("1a"), evicted.key)
require.Equal(t, 998, tlfu.slru.probation.len)

var entries2 []*Entry[StringKey, string]
entries2 := make([]*Entry[StringKey, string], 0, 1000)
for i := range 1000 {
e := NewEntry(StringKey(fmt.Sprintf("%d*", i)), "", 1)
tlfu.Set(e)
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/vtclient/cli/vtclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func (r *results) print(w io.Writer) {
code vtrpcpb.Code
count int
}
var counts []errorCounts
counts := make([]errorCounts, 0, len(r.errorCount))
for code, count := range r.errorCount {
counts = append(counts, errorCounts{code, count})
}
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/vtctldclient/command/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func commandExecuteMultiFetchAsDBA(cmd *cobra.Command, args []string) error {
return err
}

var qrs []*sqltypes.Result
qrs := make([]*sqltypes.Result, 0, len(resp.Results))
for _, result := range resp.Results {
qr := sqltypes.Proto3ToResult(result)
qrs = append(qrs, qr)
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/vtctldclient/command/vreplication/vdiff/vdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func getStructFieldNames(s any) []string {
}

func buildListings(listings []*listing) string {
var lines [][]string
lines := make([][]string, 0, len(listings)+1)
var result string

if len(listings) == 0 {
Expand Down
7 changes: 4 additions & 3 deletions go/cmd/vtgateclienttest/services/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ func newEchoClient(fallback vtgateservice.VTGateService) *echoClient {
}

func printSortedMap(val reflect.Value) []byte {
var keys []string
for _, key := range val.MapKeys() {
mapKeys := val.MapKeys()
keys := make([]string, 0, len(mapKeys))
for _, key := range mapKeys {
keys = append(keys, key.String())
}
sort.Strings(keys)
Expand All @@ -73,7 +74,7 @@ func printSortedMap(val reflect.Value) []byte {
func echoQueryResult(vals map[string]any) *sqltypes.Result {
qr := &sqltypes.Result{}

var row []sqltypes.Value
row := make([]sqltypes.Value, 0, len(vals)+2)

// The first two returned fields are always a field with a MySQL NULL value,
// and another field with a zero-length string.
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/vttablet/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestRunFailsToStartTabletManager(t *testing.T) {
"--init-tablet-type": "replica",
}

var flagArgs []string
flagArgs := make([]string, 0, len(flags))
for flag, value := range flags {
flagArgs = append(flagArgs, flag, value)
}
Expand Down
2 changes: 1 addition & 1 deletion go/event/syslogger/fake_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (tl *testLogger) getLog() loggerMsg {
}

func (tl *testLogger) GetAllLogs() []string {
var logs []string
logs := make([]string, 0, len(tl.logs))
for _, l := range tl.logs {
logs = append(logs, l.level+":"+l.msg)
}
Expand Down
3 changes: 1 addition & 2 deletions go/flagutil/flagutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ func (value StringListValue) Get() any {

func parseListWithEscapes(v string, delimiter rune) (value []string) {
var escaped, lastWasDelimiter bool
var current []rune

current := make([]rune, 0, len(v))
for _, r := range v {
lastWasDelimiter = false
if !escaped {
Expand Down
5 changes: 4 additions & 1 deletion go/mysql/binlog/binlog_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,15 @@ func binparserString(_ jsonDataType, data []byte, pos int) (node *json.Value, er
// arrays are stored thus:
// | type_identifier(one of [2,3]) | elem count | obj size | list of offsets+lengths of values | actual values |
func binparserArray(typ jsonDataType, data []byte, pos int) (node *json.Value, err error) {
var nodes []*json.Value
var elem *json.Value
var elementCount int
large := typ == jsonLargeArray
elementCount, pos = readInt(data, pos, large)
_, pos = readInt(data, pos, large)
if elementCount == 0 {
return json.NewArray(nil), nil
}
nodes := make([]*json.Value, 0, elementCount)
for range elementCount {
elem, pos, err = binparserElement(data, pos, large)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/collations/colldata/uca_contraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (s *strgen) withText(in string) *strgen {
}

func (s *strgen) generate(length int, freq float64) (out []byte) {
var flat []rune
flat := make([]rune, 0, len(s.repertoire))
for r := range s.repertoire {
flat = append(flat, r)
}
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/collations/colldata/wildcard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func BenchmarkWildcardMatching(b *testing.B) {
m2 WildcardPattern
}

var patterns []bench
patterns := make([]bench, 0, len(wildcardTestCases))
for _, tc := range wildcardTestCases {
patterns = append(patterns, bench{
input: []byte(tc.in),
Expand Down
4 changes: 2 additions & 2 deletions go/mysql/collations/golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ func XTestSupportTables(t *testing.T) {
collverMariaDB100,
}

var envs []*Environment
envs := make([]*Environment, 0, len(versions))
for _, v := range versions {
envs = append(envs, makeEnv(v))
}

var all []ID
all := make([]ID, 0, len(globalVersionInfo))
for id := range globalVersionInfo {
all = append(all, id)
}
Expand Down
5 changes: 3 additions & 2 deletions go/mysql/collations/integration/coercion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ func (tc *testComparison) Test(t *testing.T, remote *RemoteCoercionResult, local

func TestComparisonSemantics(t *testing.T) {
const BaseString = "abcdABCD01234"
var testInputs []*TextWithCollation

conn := mysqlconn(t)
defer conn.Close()
Expand All @@ -133,7 +132,9 @@ func TestComparisonSemantics(t *testing.T) {
t.Skipf("The behavior of Coercion Semantics is not correct before 8.0.31")
}

for _, coll := range colldata.All(collations.MySQL8()) {
allCollations := colldata.All(collations.MySQL8())
testInputs := make([]*TextWithCollation, 0, len(allCollations))
for _, coll := range allCollations {
text := verifyTranscoding(t, coll, remote.NewCollation(conn, coll.Name()), []byte(BaseString))
testInputs = append(testInputs, &TextWithCollation{Text: text, Collation: coll.ID()})
}
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/collations/integration/weight_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestWeightStringsComprehensive(t *testing.T) {
c4cs.remotes = append(c4cs.remotes, remote.NewCollation(conn, coll.Name()))
}

var allCharsets []*collationsForCharset
allCharsets := make([]*collationsForCharset, 0, len(charsetMap))
for _, c4cs := range charsetMap {
allCharsets = append(allCharsets, c4cs)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (g *Generator) WriteToFile(out string) {
fmt.Fprintf(&file, "package %s\n\n", g.local.Name())
fmt.Fprintf(&file, "import (\n")

var sortedPackages []Package
sortedPackages := make([]Package, 0, len(g.imported))
for pkg := range g.imported {
sortedPackages = append(sortedPackages, pkg)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (tg *TableGenerator) writePage(g *Generator, p *page, layout uca.Layout) st
}

func (tg *TableGenerator) WriteTables(g *Generator, layout uca.Layout) {
var pagePtrs []string
pagePtrs := make([]string, 0, len(tg.pages))
for _, page := range tg.pages {
pagePtrs = append(pagePtrs, tg.writePage(g, &page, layout))
}
Expand Down
4 changes: 2 additions & 2 deletions go/mysql/collations/tools/makecolldata/mysqlversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func makeversions(output string) {
}
}

var versions []string
versions := make([]string, 0, len(versionfiles))
for _, versionCsv := range versionfiles {
base := filepath.Base(versionCsv)
base = strings.TrimPrefix(base, "collations_")
Expand Down Expand Up @@ -158,7 +158,7 @@ func makeversions(output string) {
g.P()
g.P("var globalVersionInfo = map[ID]struct{alias []collalias; isdefault collver}{")

var sorted []*versionInfo
sorted := make([]*versionInfo, 0, len(versioninfo))
for _, vi := range versioninfo {
sorted = append(sorted, vi)
}
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/collations/tools/maketestdata/maketestdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func getTextFromWikipedia(lang testutil.Lang, article string) (string, error) {
return "", err
}

var chunks []string
chunks := make([]string, 0, len(response.Query.Pages))
for _, page := range response.Query.Pages {
chunks = append(chunks, page.Extract)
}
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/fakesqldb/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ func (db *DB) MockQueriesForTable(table string, result *sqltypes.Result) {
db.AddQueryPattern(selectQueryPattern, result)

// mock query for returning columns from information_schema.columns based on specified result
var cols []string
cols := make([]string, 0, len(result.Fields))
for _, field := range result.Fields {
cols = append(cols, field.Name)
}
Expand Down
14 changes: 8 additions & 6 deletions go/sqltypes/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ func ReplaceFields(result *Result, remap map[string]string) *Result {
}
}

var fields []*querypb.Field
fields := make([]*querypb.Field, 0, len(fieldIdx))
for _, name := range fieldIdx {
fields = append(fields, result.Fields[orig[name]])
}

fields = fields[:len(result.Fields)-len(remap)]

var rows []Row
rows := make([]Row, 0, len(result.Rows))
for _, origRow := range result.Rows {
var row []Value
for _, name := range rowIdx {
Expand Down Expand Up @@ -142,13 +142,15 @@ func MarshalResult(v any) (*Result, error) {
elem := val.Type().Elem()
elemType := elem.Elem()

visibleFields := reflect.VisibleFields(elemType)

var (
exportedStructFields []reflect.StructField
fields []*querypb.Field
rows []Row
exportedStructFields = make([]reflect.StructField, 0, len(visibleFields))
fields = make([]*querypb.Field, 0, len(visibleFields))
rows = make([]Row, 0, val.Len())
Comment on lines +148 to +150
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude pointed out here that the len(visibleFields) will most likely over-allocate, because not all fields might be exported. I don't think that's an issue, just potentially wasteful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is expected because we sometimes continue. But an upper limit should be more efficient than a capacity of zero

)

for _, field := range reflect.VisibleFields(elemType) {
for _, field := range visibleFields {
if !field.IsExported() {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion go/sqltypes/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (
func MakeTestFields(names, types string) []*querypb.Field {
n := split(names)
t := split(types)
var fields []*querypb.Field
fields := make([]*querypb.Field, 0, len(n))
for i := range n {
fields = append(fields, &querypb.Field{
Name: n[i],
Expand Down
2 changes: 1 addition & 1 deletion go/stats/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func makeLabels(labelNames []string, labelValsCombined string) []string {
}

func makeCommonTags(tags map[string]string) []string {
var commonTags []string
commonTags := make([]string, 0, len(tags))
for k, v := range tags {
commonTag := fmt.Sprintf("%s:%s", k, v)
commonTags = append(commonTags, commonTag)
Expand Down
Loading
Loading