Skip to content

Commit cb78e8d

Browse files
committed
Avoid using Reverse to sort in descending order, update comments
1 parent e61f296 commit cb78e8d

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

pkg/epp/flowcontrol/controller/internal/processor_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import (
4444
"errors"
4545
"fmt"
4646
"os"
47-
"slices"
47+
"sort"
4848
"sync"
4949
"sync/atomic"
5050
"testing"
@@ -256,8 +256,10 @@ func (h *testHarness) allOrderedPriorityLevels() []int {
256256
for p := range h.priorityFlows {
257257
prios = append(prios, p)
258258
}
259-
slices.Sort(prios)
260-
slices.Reverse(prios)
259+
sort.Slice(prios, func(i, j int) bool {
260+
return prios[i] > prios[j]
261+
})
262+
261263
return prios
262264
}
263265

pkg/epp/flowcontrol/registry/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ type Config struct {
112112
// that operate at this priority level.
113113
type PriorityBandConfig struct {
114114
// Priority is the unique numerical priority level for this band.
115-
// Convention: Lower numerical values indicate lower priority (e.g., 0 is lowest).
115+
// Convention: Lower numerical values indicate lower priority.
116116
// Required.
117117
Priority int
118118

pkg/epp/flowcontrol/registry/shard.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package registry
1818

1919
import (
2020
"fmt"
21-
"slices"
21+
"sort"
2222
"sync"
2323
"sync/atomic"
2424

@@ -133,9 +133,9 @@ func newShard(
133133
}
134134
s.orderedPriorityLevels = append(s.orderedPriorityLevels, bandConfig.Priority)
135135
}
136-
137-
slices.Sort(s.orderedPriorityLevels)
138-
slices.Reverse(s.orderedPriorityLevels)
136+
sort.Slice(s.orderedPriorityLevels, func(i, j int) bool {
137+
return s.orderedPriorityLevels[i] > s.orderedPriorityLevels[j]
138+
})
139139
s.logger.V(logging.DEFAULT).Info("Registry shard initialized successfully",
140140
"priorityBandCount", len(s.priorityBands), "orderedPriorities", s.orderedPriorityLevels)
141141
return s, nil

0 commit comments

Comments
 (0)