@@ -344,24 +344,24 @@ func bindRoutesToListeners(
344
344
345
345
isolateL7RouteListeners (routes , gw .Listeners )
346
346
347
- l4routes := make ([]* L4Route , 0 , len (l4Routes ))
347
+ l4RouteSlice := make ([]* L4Route , 0 , len (l4Routes ))
348
348
for _ , r := range l4Routes {
349
- l4routes = append (l4routes , r )
349
+ l4RouteSlice = append (l4RouteSlice , r )
350
350
}
351
351
352
352
// 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 )
355
355
})
356
356
357
357
// portHostnamesMap exists to detect duplicate hostnames on the same port
358
358
portHostnamesMap := make (map [string ]struct {})
359
359
360
- for _ , r := range l4routes {
360
+ for _ , r := range l4RouteSlice {
361
361
bindL4RouteToListeners (r , gw , namespaces , portHostnamesMap )
362
362
}
363
363
364
- isolateL4RouteListeners (l4routes , gw .Listeners )
364
+ isolateL4RouteListeners (l4RouteSlice , gw .Listeners )
365
365
}
366
366
367
367
// isolateL7RouteListeners ensures listener isolation for all L7Routes.
@@ -395,7 +395,7 @@ func isolateHostnamesForParentRefs(parentRef []ParentRef, listenerHostnameMap ma
395
395
for _ , ref := range parentRef {
396
396
acceptedHostnames := ref .Attachment .AcceptedHostnames
397
397
398
- hostnamesToRemoves := make ([] string , 0 , len (acceptedHostnames ))
398
+ hostnamesToRemoves := make (map [ string ] struct {} , len (acceptedHostnames ))
399
399
for listenerName , hostnames := range acceptedHostnames {
400
400
if len (hostnames ) == 0 {
401
401
continue
@@ -407,7 +407,7 @@ func isolateHostnamesForParentRefs(parentRef []ParentRef, listenerHostnameMap ma
407
407
continue
408
408
}
409
409
if h == lHostname && listenerName != lName {
410
- hostnamesToRemoves = append ( hostnamesToRemoves , h )
410
+ hostnamesToRemoves [ h ] = struct {}{}
411
411
}
412
412
}
413
413
}
@@ -419,18 +419,11 @@ func isolateHostnamesForParentRefs(parentRef []ParentRef, listenerHostnameMap ma
419
419
}
420
420
421
421
// 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 {
423
423
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 )
434
427
}
435
428
}
436
429
return result
0 commit comments