Skip to content

Commit

Permalink
fix: fix slice init length (#8091)
Browse files Browse the repository at this point in the history
  • Loading branch information
cuishuang authored Oct 5, 2024
1 parent 77ab341 commit c27d3d9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion grove/remap/remap.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (r literalPrefixRemapper) Remap(s string) (remapdata.RemapRule, bool) {
}

func (r literalPrefixRemapper) Rules() []remapdata.RemapRule {
rules := make([]remapdata.RemapRule, len(r.remap))
rules := make([]remapdata.RemapRule, 0, len(r.remap))
for _, rule := range r.remap {
rules = append(rules, rule)
}
Expand Down
2 changes: 1 addition & 1 deletion grove/stat/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (s statsRemaps) Stats(rule string) (StatsRemap, bool) {
}

func (s statsRemaps) Rules() []string {
rules := make([]string, len(s))
rules := make([]string, 0, len(s))
for rule := range s {
rules = append(rules, rule)
}
Expand Down
2 changes: 1 addition & 1 deletion traffic_ops/traffic_ops_golang/monitoring/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func getProfiles(tx *sql.Tx, caches []Cache, routers []Router) ([]Profile, error
}
}

profilesArr := make([]Profile, len([]Profile{}))
profilesArr := make([]Profile, 0, len([]Profile{}))
for _, profile := range profiles {
profilesArr = append(profilesArr, profile)
}
Expand Down
4 changes: 2 additions & 2 deletions traffic_ops/traffic_ops_golang/topology/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func checkForSelfParents(nodes []tc.TopologyNode, index int) error {
func checkForEdgeParents(topology tc.TopologyV5, cacheGroups []tc.CacheGroupNullable, nodeIndex int) (tc.Alerts, error) {
var alerts tc.Alerts
node := topology.Nodes[nodeIndex]
errs := make([]error, len(node.Parents))
errs := make([]error, 0, len(node.Parents))
for parentIndex, parentCacheGroupIndex := range node.Parents {
if parentCacheGroupIndex < 0 || parentCacheGroupIndex >= len(topology.Nodes) {
errs = append(errs, fmt.Errorf("parent %d of cachegroup %s refers to a cachegroup at index %d, but no such cachegroup exists", parentIndex, node.Cachegroup, parentCacheGroupIndex))
Expand Down Expand Up @@ -99,7 +99,7 @@ func checkForEdgeParents(topology tc.TopologyV5, cacheGroups []tc.CacheGroupNull
// an edge parents an edge, and returns an error if an edge parents a non-edge cachegroup.
func (topology *TOTopology) checkForEdgeParents(cacheGroups []tc.CacheGroupNullable, nodeIndex int) error {
node := topology.Nodes[nodeIndex]
errs := make([]error, len(node.Parents))
errs := make([]error, 0, len(node.Parents))
for parentIndex, parentCacheGroupIndex := range node.Parents {
if parentCacheGroupIndex < 0 || parentCacheGroupIndex >= len(topology.Nodes) {
errs = append(errs, fmt.Errorf("parent %d of cachegroup %s refers to a cachegroup at index %d, but no such cachegroup exists", parentIndex, node.Cachegroup, parentCacheGroupIndex))
Expand Down

0 comments on commit c27d3d9

Please sign in to comment.