Skip to content

Conversation

@kolyshkin
Copy link
Collaborator

@kolyshkin kolyshkin commented Jan 7, 2026

It looks like listUnitsInternal performs an unnecessary conversion from [][]any to []any. Also, its code has been copied over a few times, with the only change to resulting type.

Introduce generic helper functions convertSlice and storeSlice to eliminate duplicated code. Also, remove unnecessary intermediate slice allocation and conversion.

This change:

  • Adds convertSlice[T] to convert []any to typed slices
  • Adds storeSlice[T] to fetch and convert D-Bus results
  • Updates 9 functions to use the new helpers
  • Removes ~150 lines of duplicated code
  • Eliminates listUnitsInternal and listUnitFilesInternal wrappers

All functionality is preserved and tests pass.

Co-Authored-By: Claude Sonnet 4.5

Copy link
Collaborator

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

LGTM, not a huge fan of how go generics look but the deduplication does indeed look quite nice here.

It looks like listUnitsInternal performs an unnecessary conversion
from [][]any to []any. Also, its code has been copied over a few
times, with the only change to resulting type.

Introduce generic helper functions convertSlice and storeSlice to
eliminate duplicated code. Also, remove unnecessary intermediate slice
allocation and conversion.

This change:
- Adds convertSlice[T] to convert []any to typed slices
- Adds storeSlice[T] to fetch and convert D-Bus results
- Updates 9 functions to use the new helpers
- Removes ~150 lines of duplicated code
- Eliminates listUnitsInternal and listUnitFilesInternal wrappers

All functionality is preserved and tests pass.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Signed-off-by: Kir Kolyshkin <[email protected]>
@Luap99 Luap99 enabled auto-merge (rebase) January 21, 2026 13:11
@Luap99 Luap99 merged commit 2c3ebed into coreos:main Jan 21, 2026
20 checks passed
@kolyshkin kolyshkin added this to the v22.7.0 milestone Jan 28, 2026
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.

2 participants