@@ -344,24 +344,24 @@ func bindRoutesToListeners(
344344
345345 isolateL7RouteListeners (routes , gw .Listeners )
346346
347- l4routes := make ([]* L4Route , 0 , len (l4Routes ))
347+ l4RouteSlice := make ([]* L4Route , 0 , len (l4Routes ))
348348 for _ , r := range l4Routes {
349- l4routes = append (l4routes , r )
349+ l4RouteSlice = append (l4RouteSlice , r )
350350 }
351351
352352 // Sort the slice by timestamp and name so that we process the routes in the priority order
353- sort .Slice (l4routes , func (i , j int ) bool {
354- return ngfSort .LessClientObject (l4routes [i ].Source , l4routes [j ].Source )
353+ sort .Slice (l4RouteSlice , func (i , j int ) bool {
354+ return ngfSort .LessClientObject (l4RouteSlice [i ].Source , l4RouteSlice [j ].Source )
355355 })
356356
357357 // portHostnamesMap exists to detect duplicate hostnames on the same port
358358 portHostnamesMap := make (map [string ]struct {})
359359
360- for _ , r := range l4routes {
360+ for _ , r := range l4RouteSlice {
361361 bindL4RouteToListeners (r , gw , namespaces , portHostnamesMap )
362362 }
363363
364- isolateL4RouteListeners (l4routes , gw .Listeners )
364+ isolateL4RouteListeners (l4RouteSlice , gw .Listeners )
365365}
366366
367367// isolateL7RouteListeners ensures listener isolation for all L7Routes.
@@ -395,7 +395,7 @@ func isolateHostnamesForParentRefs(parentRef []ParentRef, listenerHostnameMap ma
395395 for _ , ref := range parentRef {
396396 acceptedHostnames := ref .Attachment .AcceptedHostnames
397397
398- hostnamesToRemoves := make ([] string , 0 , len (acceptedHostnames ))
398+ hostnamesToRemoves := make (map [ string ] struct {} , len (acceptedHostnames ))
399399 for listenerName , hostnames := range acceptedHostnames {
400400 if len (hostnames ) == 0 {
401401 continue
@@ -407,7 +407,7 @@ func isolateHostnamesForParentRefs(parentRef []ParentRef, listenerHostnameMap ma
407407 continue
408408 }
409409 if h == lHostname && listenerName != lName {
410- hostnamesToRemoves = append ( hostnamesToRemoves , h )
410+ hostnamesToRemoves [ h ] = struct {}{}
411411 }
412412 }
413413 }
@@ -419,18 +419,11 @@ func isolateHostnamesForParentRefs(parentRef []ParentRef, listenerHostnameMap ma
419419}
420420
421421// removeHostnames removes the hostnames that are part of toRemove slice.
422- func removeHostnames (hostnames []string , toRemove [] string ) []string {
422+ func removeHostnames (hostnames []string , toRemove map [ string ] struct {} ) []string {
423423 result := make ([]string , 0 , len (hostnames ))
424- for _ , h := range hostnames {
425- keep := true
426- for _ , r := range toRemove {
427- if h == r {
428- keep = false
429- break
430- }
431- }
432- if keep {
433- result = append (result , h )
424+ for _ , hostname := range hostnames {
425+ if _ , exists := toRemove [hostname ]; ! exists {
426+ result = append (result , hostname )
434427 }
435428 }
436429 return result
0 commit comments