You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by zr...@apache.org on 2024/10/05 01:47:10 UTC

(trafficcontrol) branch master updated: fix: fix slice init length (#8091)

This is an automated email from the ASF dual-hosted git repository.

zrhoffman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new c27d3d996d fix: fix slice init length (#8091)
c27d3d996d is described below

commit c27d3d996df26c17953a093af592c96c02485946
Author: cui fliter <im...@gmail.com>
AuthorDate: Sat Oct 5 09:47:04 2024 +0800

    fix: fix slice init length (#8091)
---
 grove/remap/remap.go                                    | 2 +-
 grove/stat/stats.go                                     | 2 +-
 traffic_ops/traffic_ops_golang/monitoring/monitoring.go | 2 +-
 traffic_ops/traffic_ops_golang/topology/validation.go   | 4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/grove/remap/remap.go b/grove/remap/remap.go
index a8253a1aa9..21241ee7d0 100644
--- a/grove/remap/remap.go
+++ b/grove/remap/remap.go
@@ -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)
 	}
diff --git a/grove/stat/stats.go b/grove/stat/stats.go
index f0c9cc6815..c7bcd5f96c 100644
--- a/grove/stat/stats.go
+++ b/grove/stat/stats.go
@@ -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)
 	}
diff --git a/traffic_ops/traffic_ops_golang/monitoring/monitoring.go b/traffic_ops/traffic_ops_golang/monitoring/monitoring.go
index e417c3f791..eec224b85e 100644
--- a/traffic_ops/traffic_ops_golang/monitoring/monitoring.go
+++ b/traffic_ops/traffic_ops_golang/monitoring/monitoring.go
@@ -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)
 	}
diff --git a/traffic_ops/traffic_ops_golang/topology/validation.go b/traffic_ops/traffic_ops_golang/topology/validation.go
index 32b0d0eb17..9e03df8a96 100644
--- a/traffic_ops/traffic_ops_golang/topology/validation.go
+++ b/traffic_ops/traffic_ops_golang/topology/validation.go
@@ -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))
@@ -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))