@@ -15,20 +15,6 @@ import (
1515 "github.com/nantian-gw/gateway/internal/mesh"
1616)
1717
18- func candidateListeners (state * clusterState , gateway gatewayv1.Gateway , parentRef gatewayv1.ParentReference ) []gatewayv1.Listener {
19- out := make ([]gatewayv1.Listener , 0 , len (gateway .Spec .Listeners ))
20- for _ , listener := range gateway .Spec .Listeners {
21- if parentRef .SectionName != nil && listener .Name != * parentRef .SectionName {
22- continue
23- }
24- if parentRef .Port != nil && listener .Port != * parentRef .Port {
25- continue
26- }
27- out = append (out , listener )
28- }
29- return out
30- }
31-
3218func serviceParentPortMatches (service corev1.Service , parentRef gatewayv1.ParentReference ) bool {
3319 if parentRef .Port == nil {
3420 return true
@@ -269,7 +255,12 @@ func referenceGrantToAllowed(items []gatewayv1beta1.ReferenceGrantTo, expected g
269255}
270256
271257func httpRouteBackends (route gatewayv1.HTTPRoute ) []backendInput {
272- out := make ([]backendInput , 0 )
258+ total := 0
259+ for _ , rule := range route .Spec .Rules {
260+ total += len (rule .BackendRefs )
261+ }
262+
263+ out := make ([]backendInput , 0 , total )
273264 for _ , rule := range route .Spec .Rules {
274265 for _ , backendRef := range rule .BackendRefs {
275266 out = append (out , backendInput {
@@ -285,7 +276,12 @@ func httpRouteBackends(route gatewayv1.HTTPRoute) []backendInput {
285276}
286277
287278func grpcRouteBackends (route gatewayv1.GRPCRoute ) []backendInput {
288- out := make ([]backendInput , 0 )
279+ total := 0
280+ for _ , rule := range route .Spec .Rules {
281+ total += len (rule .BackendRefs )
282+ }
283+
284+ out := make ([]backendInput , 0 , total )
289285 for _ , rule := range route .Spec .Rules {
290286 for _ , backendRef := range rule .BackendRefs {
291287 out = append (out , backendInput {
@@ -301,7 +297,12 @@ func grpcRouteBackends(route gatewayv1.GRPCRoute) []backendInput {
301297}
302298
303299func tcpRouteBackends (route gatewayv1alpha2.TCPRoute ) []backendInput {
304- out := make ([]backendInput , 0 )
300+ total := 0
301+ for _ , rule := range route .Spec .Rules {
302+ total += len (rule .BackendRefs )
303+ }
304+
305+ out := make ([]backendInput , 0 , total )
305306 for _ , rule := range route .Spec .Rules {
306307 for _ , backendRef := range rule .BackendRefs {
307308 out = append (out , backendInput {
@@ -317,7 +318,12 @@ func tcpRouteBackends(route gatewayv1alpha2.TCPRoute) []backendInput {
317318}
318319
319320func udpRouteBackends (route gatewayv1alpha2.UDPRoute ) []backendInput {
320- out := make ([]backendInput , 0 )
321+ total := 0
322+ for _ , rule := range route .Spec .Rules {
323+ total += len (rule .BackendRefs )
324+ }
325+
326+ out := make ([]backendInput , 0 , total )
321327 for _ , rule := range route .Spec .Rules {
322328 for _ , backendRef := range rule .BackendRefs {
323329 out = append (out , backendInput {
@@ -333,7 +339,12 @@ func udpRouteBackends(route gatewayv1alpha2.UDPRoute) []backendInput {
333339}
334340
335341func tlsRouteBackends (route gatewayv1alpha2.TLSRoute ) []backendInput {
336- out := make ([]backendInput , 0 )
342+ total := 0
343+ for _ , rule := range route .Spec .Rules {
344+ total += len (rule .BackendRefs )
345+ }
346+
347+ out := make ([]backendInput , 0 , total )
337348 for _ , rule := range route .Spec .Rules {
338349 for _ , backendRef := range rule .BackendRefs {
339350 out = append (out , backendInput {
0 commit comments