Skip to content

refactor: use slices and maps stdlib functions instead of manual implementations#2021

Open
dgageot wants to merge 1 commit intodocker:mainfrom
dgageot:board/identify-places-in-the-code-where-we-cou-b5ba687d
Open

refactor: use slices and maps stdlib functions instead of manual implementations#2021
dgageot wants to merge 1 commit intodocker:mainfrom
dgageot:board/identify-places-in-the-code-where-we-cou-b5ba687d

Conversation

@dgageot
Copy link
Member

@dgageot dgageot commented Mar 9, 2026

Replace manual loops and sort package usage with idiomatic Go stdlib functions from the slices and maps packages across 18 files:

  • sort.Stringsslices.Sort
  • sort.Sliceslices.SortFunc
  • sort.SliceStableslices.SortStableFunc
  • append([]T(nil), src...)slices.Clone
  • Manual map-key collection → slices.Collect(maps.Keys(...))
  • Manual map clone → maps.Clone
  • Manual reverse loop → slices.Reverse
  • Manual slice concat → slices.Concat
  • Collect keys + sort → slices.Sorted(maps.Keys(...))

All changes are semantically equivalent to the original code. Linter passes, all unit tests pass.

…ementations

Replace manual loops and sort package usage with idiomatic Go stdlib
functions from the slices and maps packages across 18 files:

- sort.Strings -> slices.Sort
- sort.Slice -> slices.SortFunc
- sort.SliceStable -> slices.SortStableFunc
- append([]T(nil), src...) -> slices.Clone
- manual map-key collection -> slices.Collect(maps.Keys(...))
- manual map clone -> maps.Clone
- manual reverse loop -> slices.Reverse
- manual slice concat -> slices.Concat
- collect keys + sort -> slices.Sorted(maps.Keys(...))

Assisted-By: docker-agent
@dgageot dgageot requested a review from a team as a code owner March 9, 2026 20:33
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Assessment: 🟢 APPROVE

This PR successfully refactors manual loop implementations to use idiomatic Go stdlib functions from the slices and maps packages. The changes are semantically equivalent to the original code with no bugs detected.

Key Changes Verified:

  • sort.Stringsslices.Sort (3 files)
  • sort.Sliceslices.SortFunc (5 files)
  • sort.SliceStableslices.SortStableFunc (1 file)
  • append([]T(nil), src...)slices.Clone (6 files)
  • ✅ Manual map-key collection → slices.Collect(maps.Keys(...)) (3 files)
  • ✅ Manual map clone → maps.Clone (1 file)
  • ✅ Manual reverse loop → slices.Reverse (1 file)
  • ✅ Manual slice concat → slices.Concat (2 files)
  • ✅ Collect keys + sort → slices.Sorted(maps.Keys(...)) (1 file)

All comparison functions in slices.SortFunc and slices.SortStableFunc use the correct cmp.Compare logic that maintains the original sort order semantics. No behavioral changes, nil handling issues, or off-by-one errors detected.

The refactoring improves code readability and aligns with modern Go idioms (Go 1.21+).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant