mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
linter: prealloc (#2315)
This commit is contained in:
parent
d2856bfeee
commit
c79cc3b7db
14 changed files with 23 additions and 20 deletions
|
|
@ -25,7 +25,7 @@ linters:
|
|||
- errname
|
||||
- gofmt
|
||||
# - misspell (lots to fix, but we should)
|
||||
# - prealloc (15 to fix)
|
||||
- prealloc
|
||||
# - predeclared (20 to fix)
|
||||
# - stylecheck (quite a lot to fix, but we should definitely work on this)
|
||||
# - unconvert (not at all critical, but makes for cleaner code)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/featurebasedb/featurebase/v3"
|
||||
pilosa "github.com/featurebasedb/featurebase/v3"
|
||||
)
|
||||
|
||||
// Ensure cache stays constrained to its configured size.
|
||||
|
|
@ -62,7 +62,7 @@ func TestCache_Rank_Dirty(t *testing.T) {
|
|||
cache.Add(v.ID, v.Count)
|
||||
}
|
||||
|
||||
var got []pair
|
||||
var got []pair //nolint:prealloc
|
||||
for _, p := range cache.Top() {
|
||||
got = append(got, pair(p))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -459,7 +459,7 @@ func (t *Table) HasValidPrimaryKey() bool {
|
|||
|
||||
// FieldNames returns the list of field names associated with the table.
|
||||
func (t *Table) FieldNames() []FieldName {
|
||||
var ret []FieldName
|
||||
ret := make([]FieldName, 0, len(t.Fields))
|
||||
for _, f := range t.Fields {
|
||||
ret = append(ret, f.Name)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ func (c *CallStats) Report(title string) (r string) {
|
|||
r = fmt.Sprintf("CallStats: (%v)\n", title)
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
var lines []*LineSorter
|
||||
lines := make([]*LineSorter, 0, len(c.elap))
|
||||
for id, elap := range c.elap {
|
||||
slc := elap.dur
|
||||
n := len(slc)
|
||||
|
|
|
|||
|
|
@ -134,8 +134,9 @@ func (e *EmbeddedEtcd) Shutdown() {
|
|||
}
|
||||
|
||||
func (e *EmbeddedEtcd) Peers() []*disco.Peer {
|
||||
var peers []*disco.Peer
|
||||
for _, member := range e.e.Server.Cluster().Members() {
|
||||
members := e.e.Server.Cluster().Members()
|
||||
peers := make([]*disco.Peer, 0, len(members))
|
||||
for _, member := range members {
|
||||
peers = append(peers, &disco.Peer{ID: member.ID.String(), URL: member.PickPeerURL()})
|
||||
}
|
||||
return peers
|
||||
|
|
|
|||
|
|
@ -2321,7 +2321,7 @@ func (e *executor) executeTopKShardTime(ctx context.Context, tx Tx, filter *Row,
|
|||
}
|
||||
|
||||
// Fetch fragments.
|
||||
var fragments []*fragment
|
||||
fragments := make([]*fragment, 0, len(views))
|
||||
for _, view := range views {
|
||||
f := e.Holder.fragment(index, field, view, shard)
|
||||
if f == nil {
|
||||
|
|
|
|||
|
|
@ -7620,7 +7620,7 @@ func variousQueriesOnPercentiles(t *testing.T, c *test.Cluster) {
|
|||
}
|
||||
|
||||
// generate string-set entries for index
|
||||
var stringEntries [][2]string
|
||||
stringEntries := make([][2]string, 0, len(testValues))
|
||||
for _, v := range testValues {
|
||||
stringEntries = append(stringEntries,
|
||||
[2]string{v.rowKey, v.colKey})
|
||||
|
|
@ -7657,7 +7657,7 @@ func variousQueriesOnPercentiles(t *testing.T, c *test.Cluster) {
|
|||
|
||||
// generate test cases per each nth argument
|
||||
nthsFloat := []float64{0, 10, 25, 50, 75, 90, 99}
|
||||
var tests []testCase
|
||||
tests := make([]testCase, 0, len(nthsFloat))
|
||||
for _, nth := range nthsFloat {
|
||||
query := fmt.Sprintf(`Percentile(field="net_worth", filter=Row(val="foo"), nth=%f)`, nth)
|
||||
expectedPercentile := getExpectedPercentile(nums, nth)
|
||||
|
|
|
|||
5
field.go
5
field.go
|
|
@ -1018,8 +1018,9 @@ func (f *Field) viewsByTimeRange(from, to time.Time) (views []string, err error)
|
|||
}
|
||||
|
||||
// Get min/max based on existing views.
|
||||
var vs []string
|
||||
for _, v := range f.views() {
|
||||
fv := f.views()
|
||||
vs := make([]string, 0, len(fv))
|
||||
for _, v := range fv {
|
||||
vs = append(vs, v.name)
|
||||
}
|
||||
min, max := minMaxViews(vs, q)
|
||||
|
|
|
|||
|
|
@ -2907,8 +2907,9 @@ const (
|
|||
|
||||
// parseUint64Slice returns a slice of uint64s from a comma-delimited string.
|
||||
func parseUint64Slice(s string) ([]uint64, error) {
|
||||
var a []uint64
|
||||
for _, str := range strings.Split(s, ",") {
|
||||
ss := strings.Split(s, ",")
|
||||
a := make([]uint64, 0, len(ss))
|
||||
for _, str := range ss {
|
||||
// Ignore blanks.
|
||||
if str == "" {
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -493,7 +493,7 @@ func (c *Cursor) putLeafCell(in leafCell) (err error) {
|
|||
|
||||
// Write each group to a separate page.
|
||||
newRoot := (len(groups) > 1) && (c.stack.top == 0)
|
||||
var parents []branchCell
|
||||
parents := make([]branchCell, 0, len(groups))
|
||||
origPgno := elem.pgno
|
||||
// newRoot if split occured and bottom of the stack
|
||||
for i, group := range groups {
|
||||
|
|
@ -724,7 +724,7 @@ func (c *Cursor) putBranchCells(stackIndex int, newCells []branchCell) (err erro
|
|||
}
|
||||
|
||||
// Write each group to a separate page.
|
||||
var parents []branchCell
|
||||
parents := make([]branchCell, 0, len(groups))
|
||||
origPgno := readPageNo(page)
|
||||
newRoot := len(groups) > 1 && stackIndex == 0
|
||||
for i, group := range groups {
|
||||
|
|
|
|||
|
|
@ -332,7 +332,7 @@ func TestCursor_putBranchCellsHandlesLotsOfNewBranchesAtTheRoot(t *testing.T) {
|
|||
|
||||
groups := splitLeafCells(leafcells)
|
||||
|
||||
var branches []branchCell
|
||||
branches := make([]branchCell, 0, len(groups))
|
||||
|
||||
for i, group := range groups {
|
||||
_ = i
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ func (h handlerSelectFieldsFromTableWhere) Apply(stmt *sqlparser.Select, qm Quer
|
|||
return nil, errors.Wrap(err, "extracting select fields")
|
||||
}
|
||||
|
||||
var fields []string
|
||||
var fields []string //nolint:prealloc
|
||||
for _, fld := range selectFields {
|
||||
if _, ok := fld.(*StarColumn); ok {
|
||||
pflds := index.Fields()
|
||||
|
|
|
|||
|
|
@ -706,7 +706,7 @@ func (n *callPlanExpression) EvaluateFormat(currentRow []interface{}) (interface
|
|||
return nil, sql3.NewErrUnexpectedTypeConversion(0, 0, argEval)
|
||||
}
|
||||
|
||||
var args []interface{}
|
||||
args := make([]interface{}, 0, len(n.args)-1)
|
||||
|
||||
// loop, since args can be of any length.
|
||||
for _, arg := range n.args[1:] {
|
||||
|
|
|
|||
2
view.go
2
view.go
|
|
@ -134,7 +134,7 @@ func (v *view) openWithShardSet(ss *shardSet) error {
|
|||
|
||||
shards := ss.CloneMaybe()
|
||||
|
||||
var frags []*fragment
|
||||
frags := make([]*fragment, 0, len(shards))
|
||||
for shard := range shards {
|
||||
frag := v.newFragment(shard)
|
||||
frags = append(frags, frag)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue