Skip to content

Commit

Permalink
pkg/cri: optimize slice initialization
Browse files Browse the repository at this point in the history
Some of this code was originally added in b7b1200,
which likely meant to initialize the slice with a length to reduce allocations,
however, instead of initializing with a zero-length and a capacity, it
initialized the slice with a fixed length, which was corrected in commit
0c63c42.

This patch initializes the slice with a zero-length and expected capacity.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 4f39b16)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Jan 24, 2023
1 parent e6cf5ec commit ab193eb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/cri/server/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ func copyResourcesToStatus(spec *runtimespec.Spec, status containerstore.Status)
}

if spec.Linux.Resources.HugepageLimits != nil {
hugepageLimits := make([]*runtime.HugepageLimit, 0)
hugepageLimits := make([]*runtime.HugepageLimit, 0, len(spec.Linux.Resources.HugepageLimits))
for _, l := range spec.Linux.Resources.HugepageLimits {
hugepageLimits = append(hugepageLimits, &runtime.HugepageLimit{
PageSize: l.Pagesize,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cri/store/container/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func deepCopyOf(s Status) Status {
}
copy.Resources = &runtime.ContainerResources{}
if s.Resources != nil && s.Resources.Linux != nil {
hugepageLimits := make([]*runtime.HugepageLimit, 0)
hugepageLimits := make([]*runtime.HugepageLimit, 0, len(s.Resources.Linux.HugepageLimits))
for _, l := range s.Resources.Linux.HugepageLimits {
if l != nil {
hugepageLimits = append(hugepageLimits, &runtime.HugepageLimit{
Expand Down

0 comments on commit ab193eb

Please sign in to comment.