Skip to content

Commit 854eabf

Browse files
committed
fix: use stable slices sort
1 parent b06bd35 commit 854eabf

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

pkg/store/types.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package store
1717
import (
1818
"fmt"
1919
"net/netip"
20-
"sort"
20+
"slices"
2121
"time"
2222

2323
"github.com/haproxytech/client-native/v6/models"
@@ -105,8 +105,14 @@ func SortedRuntimeEndpoints(endpoints RuntimeEndpoints) []RuntimeEndpoint {
105105
for endpoint := range endpoints {
106106
sortedEndpoints = append(sortedEndpoints, endpoint)
107107
}
108-
sort.SliceStable(sortedEndpoints, func(i, j int) bool {
109-
return runtimeEndpointLess(sortedEndpoints[i], sortedEndpoints[j])
108+
slices.SortStableFunc(sortedEndpoints, func(a, b RuntimeEndpoint) int {
109+
if runtimeEndpointLess(a, b) {
110+
return -1
111+
}
112+
if runtimeEndpointLess(b, a) {
113+
return 1
114+
}
115+
return 0
110116
})
111117
return sortedEndpoints
112118
}

0 commit comments

Comments
 (0)