pkg/cri: optimize slice initialization
Some of this code was originally added inb7b1200dd3
, 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 commit0c63c42f81
. This patch initializes the slice with a zero-length and expected capacity. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
403352dd3d
commit
4f39b164f3
@ -478,7 +478,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,
|
||||
|
@ -476,7 +476,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,
|
||||
|
@ -219,7 +219,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{
|
||||
|
Loading…
Reference in New Issue
Block a user