Skip to content

Refactor to use slices.SortFunc (Go 1.21+)#774

Merged
fxamacker merged 1 commit into
masterfrom
fxamacker/refactor-to-use-slices-sortfunc
May 11, 2026
Merged

Refactor to use slices.SortFunc (Go 1.21+)#774
fxamacker merged 1 commit into
masterfrom
fxamacker/refactor-to-use-slices-sortfunc

Conversation

@fxamacker
Copy link
Copy Markdown
Owner

@fxamacker fxamacker commented May 10, 2026

This PR reduces memory allocs and simplifies code by replacing the old sort.Interface implementations with slices.SortFunc():

  • bytewiseFieldSorter
  • lengthFirstFieldSorter
  • indexFieldSorter
  • bytewiseKeyValueSorter
  • lengthFirstKeyValueSorter

The main benefit is less code to maintain, with the new code being simpler and more modern. The performance improvement in the CBOR codec is modest.

Behavior of the codec is not affected by this, other than
a modest improvement in speed and memory use.

This commit replaces the following sort.Interface implementations
with slices.SortFunc() to reduce allocs and simplify code:
- bytewiseFieldSorter
- lengthFirstFieldSorter
- indexFieldSorter
- bytewiseKeyValueSorter
- lengthFirstKeyValueSorter
@fxamacker fxamacker self-assigned this May 10, 2026
@fxamacker fxamacker added performance improvement improvement that does not add new feature labels May 10, 2026
@fxamacker fxamacker changed the base branch from fxamacker/bump-min-go-version-to-124 to master May 10, 2026 21:46
@fxamacker fxamacker changed the title Refactor to use slices.SortFunc() to modernize code Refactor to use slices.SortFunc (Go 1.21+) May 11, 2026
@fxamacker fxamacker merged commit a6b110a into master May 11, 2026
17 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement improvement that does not add new feature performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants