-
Notifications
You must be signed in to change notification settings - Fork 162
refactor: replace sort.Slice with slices.Sort for natural ordering #3139
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: dulanting <[email protected]>
WalkthroughReplaced usages of sort.Slice with slices.Sort across three Go files, updating imports accordingly. No function signatures, external behavior, or error handling changed. Control flow remains the same aside from the sorting method. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
protocol/x/perpetuals/keeper/perpetual.go (1)
619-619: LGTM!The refactoring correctly replaces
sort.Slicewithslices.Sortfor natural ascending order of[]int32.Consider completing the refactoring at lines 251-253 where
sort.Sliceis still used:- sort.Slice(list, func(i, j int) bool { - return list[i].Params.Id < list[j].Params.Id - }) + slices.SortFunc(list, func(a, b types.Perpetual) int { + return int(a.Params.Id) - int(b.Params.Id) + })Note: This would require
slices.SortFuncsince we're sorting by a field, not the struct itself.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
protocol/lib/math.go(2 hunks)protocol/x/perpetuals/keeper/perpetual.go(2 hunks)protocol/x/prices/client/testutil/util.go(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Summary
🔇 Additional comments (5)
protocol/x/perpetuals/keeper/perpetual.go (1)
7-8: LGTM!Both imports are needed:
slicesfor the new Line 619 usage, andsortfor the existing Line 251 usage.protocol/lib/math.go (2)
8-8: LGTM!The import change is appropriate since
slices.Sortreplaces the previoussort.Sliceusage.
185-185: LGTM!The refactoring correctly uses
slices.Sortwith the generic ordered constraint. All types in the constraint (uint64 | uint32 | int64 | int32) support natural ordering.protocol/x/prices/client/testutil/util.go (2)
4-4: LGTM!The import change is appropriate for the new
slices.Sortusage.
15-15: LGTM!The refactoring correctly uses
slices.Sortfor natural ascending order of[]uint32.
Changelist
[Describe or list the changes made in this PR]
There is a new function added in the go1.21 standard library, which can make the code more concise and easy to read.
Test Plan
[Describe how this PR was tested (if applicable)]
Author/Reviewer Checklist
state-breakinglabel.indexer-postgres-breakinglabel.PrepareProposalorProcessProposal, manually add the labelproposal-breaking.feature:[feature-name].backport/[branch-name].refactor,chore,bug.Summary by CodeRabbit