Skip to content

Prealloc fixes#17841

Merged
tomponline merged 4 commits intocanonical:mainfrom
simondeziel:prealloc
Mar 9, 2026
Merged

Prealloc fixes#17841
tomponline merged 4 commits intocanonical:mainfrom
simondeziel:prealloc

Conversation

@simondeziel
Copy link
Copy Markdown
Member

This is in preparation of Dependabot pulling a new golangci-lint (after the 7 day cooldown) which will bring newer prealloc version.

…ersed`

Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
@simondeziel simondeziel marked this pull request as ready for review March 8, 2026 20:45
@simondeziel simondeziel requested a review from Copilot March 8, 2026 20:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Prepares LXD for an upcoming golangci-lint update by adjusting slice initialization patterns to satisfy newer prealloc linter behavior, without changing runtime logic.

Changes:

  • Preallocate inheritKeys in NIC validateConfig() paths so subsequent append() operations avoid allocations.
  • Preallocate DevicesSortable in Devices.Sorted() and Devices.Reversed() based on the number of devices.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
lxd/device/nic_sriov.go Preallocates inheritKeys to avoid allocations when building bannedKeys.
lxd/device/nic_macvlan.go Same preallocation pattern as SR-IOV for inheritKeys/bannedKeys.
lxd/device/nic_bridged.go Preallocates inheritKeys to avoid allocations when extending into bannedKeys.
lxd/device/config/devices.go Preallocates DevicesSortable slices in sorting helpers to satisfy prealloc.

@simondeziel
Copy link
Copy Markdown
Member Author

@tomponline I've put up a reminder to verify that Dependabot will pick up the new [golangci-lint version])(https://github.com/golangci/golangci-lint/releases/tag/v2.11.2) on March 23rd if I got the cooldown logic right.

@simondeziel simondeziel requested a review from tomponline March 8, 2026 20:47
@tomponline tomponline merged commit 6d28ef6 into canonical:main Mar 9, 2026
70 checks passed
@simondeziel simondeziel deleted the prealloc branch March 9, 2026 12:57
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.

3 participants