From af38c79e36ef0c92e4273f41933de8b4b8b92b8e Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 12 Oct 2022 10:18:07 +0200 Subject: [PATCH] Avoid unnecessary calls to Container.Spec() This call does a deep copy, which is only needed if you want to modify the return value. Instead we use ctr.ConfigNoCopy().Spec which is just a pointer dereference. [NO NEW TESTS NEEDED] Just minor performance effects Signed-off-by: Alexander Larsson --- pkg/specgen/generate/container.go | 2 +- pkg/specgen/generate/storage.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/specgen/generate/container.go b/pkg/specgen/generate/container.go index 736fa5ab3c..834345f4c8 100644 --- a/pkg/specgen/generate/container.go +++ b/pkg/specgen/generate/container.go @@ -474,7 +474,7 @@ func ConfigToSpec(rt *libpod.Runtime, specg *specgen.SpecGenerator, contaierID s } } specg.OverlayVolumes = overlay - _, mounts := c.SortUserVolumes(c.Spec()) + _, mounts := c.SortUserVolumes(c.ConfigNoCopy().Spec) specg.Mounts = mounts specg.HostDeviceList = conf.DeviceHostSrc specg.Networks = conf.Networks diff --git a/pkg/specgen/generate/storage.go b/pkg/specgen/generate/storage.go index c3cd61b36f..b6b80def4d 100644 --- a/pkg/specgen/generate/storage.go +++ b/pkg/specgen/generate/storage.go @@ -288,7 +288,7 @@ func getVolumesFrom(volumesFrom []string, runtime *libpod.Runtime) (map[string]s // Now we get the container's spec and loop through its volumes // and append them in if we can find them. - spec := ctr.Spec() + spec := ctr.ConfigNoCopy().Spec if spec == nil { return nil, nil, fmt.Errorf("retrieving container %s spec for volumes-from", ctr.ID()) }