Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update slices.SortFunc for Go 1.21 #4706

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ require (
go.uber.org/fx v1.20.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691
golang.org/x/oauth2 v0.9.0
golang.org/x/sync v0.3.0
golang.org/x/time v0.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1331,8 +1331,8 @@ golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691 h1:/yRP+0AN7mf5DkD3BAI6TOFnd51gEoDEb8o35jIFtgw=
golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
Expand Down
5 changes: 3 additions & 2 deletions service/history/queues/action_pending_task_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ func (a *actionQueuePendingTask) gatherStatistics(
})
}
for _, sliceList := range a.slicesPerNamespace {
slices.SortFunc(sliceList, func(this, that Slice) bool {
slices.SortFunc(sliceList, func(this, that Slice) int {
thisMin := this.Scope().Range.InclusiveMin
thatMin := that.Scope().Range.InclusiveMin
return thisMin.CompareTo(thatMin) > 0
// sort in largest to smallest order
return thisMin.CompareTo(thatMin) * -1
evanj marked this conversation as resolved.
Show resolved Hide resolved
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions service/history/queues/action_slice_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ func (a *actionSliceCount) pickCompactCandidates(
candidates []compactCandidate,
numSliceToCompact int,
) map[Slice]struct{} {
slices.SortFunc(candidates, func(this, that compactCandidate) bool {
return this.distance.CompareTo(that.distance) < 0
slices.SortFunc(candidates, func(this, that compactCandidate) int {
return this.distance.CompareTo(that.distance)
})

sliceToCompact := make(map[Slice]struct{}, numSliceToCompact)
Expand Down
4 changes: 2 additions & 2 deletions service/history/queues/queue_scheduled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func (s *scheduledQueueSuite) TestPaginationFnProvider() {
tasks.NewKey(r.InclusiveMin.FireTime.Add(time.Microsecond*10), rand.Int63()),
tasks.NewKey(r.InclusiveMin.FireTime.Add(time.Second), rand.Int63()),
}
slices.SortFunc(testTaskKeys, func(k1, k2 tasks.Key) bool {
return k1.CompareTo(k2) < 0
slices.SortFunc(testTaskKeys, func(k1, k2 tasks.Key) int {
return k1.CompareTo(k2)
})
shouldHaveNextPage := true
if testTaskKeys[len(testTaskKeys)-1].CompareTo(r.ExclusiveMax) >= 0 {
Expand Down
20 changes: 10 additions & 10 deletions service/history/queues/slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ func (s *sliceSuite) TestShrinkScope_ShrinkRange() {
slice.iterators = s.randomIteratorsInRange(r, rand.Intn(2), nil)

executables := s.randomExecutablesInRange(r, 5)
slices.SortFunc(executables, func(a, b Executable) bool {
return a.GetKey().CompareTo(b.GetKey()) < 0
slices.SortFunc(executables, func(a, b Executable) int {
return a.GetKey().CompareTo(b.GetKey())
})

firstPendingIdx := len(executables)
Expand Down Expand Up @@ -386,8 +386,8 @@ func (s *sliceSuite) TestShrinkScope_ShrinkPredicate() {
slice.iterators = []Iterator{} // manually set iterators to be empty to trigger predicate update

executables := s.randomExecutablesInRange(r, 100)
slices.SortFunc(executables, func(a, b Executable) bool {
return a.GetKey().CompareTo(b.GetKey()) < 0
slices.SortFunc(executables, func(a, b Executable) int {
return a.GetKey().CompareTo(b.GetKey())
})

pendingNamespaceID := []string{uuid.New(), uuid.New()}
Expand Down Expand Up @@ -442,8 +442,8 @@ func (s *sliceSuite) TestSelectTasks_NoError() {
mockTasks = append(mockTasks, mockTask)
}

slices.SortFunc(mockTasks, func(a, b tasks.Task) bool {
return a.GetKey().CompareTo(b.GetKey()) < 0
slices.SortFunc(mockTasks, func(a, b tasks.Task) int {
return a.GetKey().CompareTo(b.GetKey())
})

return mockTasks, nil, nil
Expand Down Expand Up @@ -491,8 +491,8 @@ func (s *sliceSuite) TestSelectTasks_Error_NoLoadedTasks() {
mockTasks = append(mockTasks, mockTask)
}

slices.SortFunc(mockTasks, func(a, b tasks.Task) bool {
return a.GetKey().CompareTo(b.GetKey()) < 0
slices.SortFunc(mockTasks, func(a, b tasks.Task) int {
return a.GetKey().CompareTo(b.GetKey())
})

return mockTasks, nil, nil
Expand Down Expand Up @@ -534,8 +534,8 @@ func (s *sliceSuite) TestSelectTasks_Error_WithLoadedTasks() {
mockTasks = append(mockTasks, mockTask)
}

slices.SortFunc(mockTasks, func(a, b tasks.Task) bool {
return a.GetKey().CompareTo(b.GetKey()) < 0
slices.SortFunc(mockTasks, func(a, b tasks.Task) int {
return a.GetKey().CompareTo(b.GetKey())
})

return mockTasks, []byte{1, 2, 3}, nil
Expand Down
4 changes: 2 additions & 2 deletions service/history/queues/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func NewRandomOrderedRangesInRange(
ranges = append(ranges[1:], left, right)
}

slices.SortFunc(ranges, func(a, b Range) bool {
return a.InclusiveMin.CompareTo(b.InclusiveMin) < 0
slices.SortFunc(ranges, func(a, b Range) int {
return a.InclusiveMin.CompareTo(b.InclusiveMin)
})

return ranges
Expand Down