Skip to content

Commit

Permalink
chore: consider perallocating (#1087)
Browse files Browse the repository at this point in the history
* consider perallocating

* chore: consider perallocating
  • Loading branch information
zjx-ERROR committed Sep 8, 2023
1 parent e0b2657 commit 2c6bb12
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/object/meshcontroller/api/api_customresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (a *API) listCustomResourceKinds(w http.ResponseWriter, r *http.Request) {
return kinds[i].Name < kinds[j].Name
})

var pbKinds []*v2alpha1.CustomResourceKind
pbKinds := make([]*v2alpha1.CustomResourceKind, 0, len(kinds))
for _, v := range kinds {
kind := &v2alpha1.CustomResourceKind{}
err := a.convertSpecToPB(v, kind)
Expand Down
2 changes: 1 addition & 1 deletion pkg/object/meshcontroller/api/api_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (a *API) listIngresses(w http.ResponseWriter, r *http.Request) {
specs := a.service.ListIngressSpecs()

sort.Sort(ingressesByOrder(specs))
var apiSpecs []*v2alpha1.Ingress
apiSpecs := make([]*v2alpha1.Ingress, 0, len(specs))
for _, v := range specs {
ingress := &v2alpha1.Ingress{}
err := a.convertSpecToPB(v, ingress)
Expand Down
2 changes: 1 addition & 1 deletion pkg/object/meshcontroller/api/api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (a *API) listServices(w http.ResponseWriter, r *http.Request) {

sort.Sort(servicesByOrder(specs))

var apiSpecs []*v2alpha1.Service
apiSpecs := make([]*v2alpha1.Service, 0, len(specs))
for _, v := range specs {
service := &v2alpha1.Service{}
err := a.convertSpecToPB(v, service)
Expand Down
4 changes: 2 additions & 2 deletions pkg/object/meshcontroller/api/api_trafficcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (a *API) listHTTPRouteGroups(w http.ResponseWriter, r *http.Request) {
return groups[i].Name < groups[j].Name
})

var pbGroups []*v2alpha1.HTTPRouteGroup
pbGroups := make([]*v2alpha1.HTTPRouteGroup, 0, len(groups))
for _, v := range groups {
group := &v2alpha1.HTTPRouteGroup{}
err := a.convertSpecToPB(v, group)
Expand Down Expand Up @@ -141,7 +141,7 @@ func (a *API) listTrafficTargets(w http.ResponseWriter, r *http.Request) {
return tts[i].Name < tts[j].Name
})

var pbTrafficTargets []*v2alpha1.TrafficTarget
pbTrafficTargets := make([]*v2alpha1.TrafficTarget, 0, len(tts))
for _, v := range tts {
tt := &v2alpha1.TrafficTarget{}
err := a.convertSpecToPB(v, tt)
Expand Down
4 changes: 2 additions & 2 deletions pkg/object/meshcontroller/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ func (s *Service) ListServiceCerts() []*spec.Certificate {

// ListAllIngressControllerInstanceCerts gets the ingress controller cert.
func (s *Service) ListAllIngressControllerInstanceCerts() []*spec.Certificate {
var certs []*spec.Certificate
values, err := s.store.GetPrefix(layout.AllIngressControllerInstanceCertPrefix())
if err != nil {
api.ClusterPanic(err)
}

certs := make([]*spec.Certificate, 0, len(values))
for _, v := range values {
cert := &spec.Certificate{}
if err = codectool.Unmarshal([]byte(v), cert); err != nil {
Expand All @@ -225,7 +225,7 @@ func (s *Service) ListAllIngressControllerInstanceCerts() []*spec.Certificate {
certs = append(certs, cert)

}
return certs
return certs[:len(certs):len(certs)]
}

// PutIngressControllerInstanceCert puts the root cert.
Expand Down
2 changes: 1 addition & 1 deletion pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func (spec *Spec) newBatchSpanProcessors() ([]sdktrace.SpanProcessor, error) {
}
}

var bsps []sdktrace.SpanProcessor
bsps := make([]sdktrace.SpanProcessor, 0, len(exporters))
for _, exp := range exporters {
bsps = append(bsps, sdktrace.NewBatchSpanProcessor(exp, opts...))
}
Expand Down

0 comments on commit 2c6bb12

Please sign in to comment.