Merge pull request #10488 from dcantah/avoid-realloc
Avoid potential reallocs by pre-sizing some slices
This commit is contained in:
commit
1e3c35bd0d
@ -274,9 +274,9 @@ func (c *Client) Containers(ctx context.Context, filters ...string) ([]Container
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var out []Container
|
out := make([]Container, len(r))
|
||||||
for _, container := range r {
|
for i, container := range r {
|
||||||
out = append(out, containerFromRecord(c, container))
|
out[i] = containerFromRecord(c, container)
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
@ -519,9 +519,9 @@ func (c *Client) Restore(ctx context.Context, id string, checkpoint Image, opts
|
|||||||
}
|
}
|
||||||
defer done(ctx)
|
defer done(ctx)
|
||||||
|
|
||||||
copts := []NewContainerOpts{}
|
copts := make([]NewContainerOpts, len(opts))
|
||||||
for _, o := range opts {
|
for i, o := range opts {
|
||||||
copts = append(copts, o(ctx, id, c, checkpoint, index))
|
copts[i] = o(ctx, id, c, checkpoint, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctr, err := c.NewContainer(ctx, id, copts...)
|
ctr, err := c.NewContainer(ctx, id, copts...)
|
||||||
|
@ -119,9 +119,9 @@ When '--all-platforms' is given all images in a manifest list must be available.
|
|||||||
exportOpts = append(exportOpts, tarchive.WithSkipNonDistributableBlobs)
|
exportOpts = append(exportOpts, tarchive.WithSkipNonDistributableBlobs)
|
||||||
}
|
}
|
||||||
|
|
||||||
storeOpts := []image.StoreOpt{}
|
storeOpts := make([]image.StoreOpt, len(images))
|
||||||
for _, img := range images {
|
for i, img := range images {
|
||||||
storeOpts = append(storeOpts, image.WithExtraReference(img))
|
storeOpts[i] = image.WithExtraReference(img)
|
||||||
}
|
}
|
||||||
|
|
||||||
return client.Transfer(ctx,
|
return client.Transfer(ctx,
|
||||||
|
@ -256,8 +256,8 @@ func onUntarBlob(ctx context.Context, r io.Reader, store content.Ingester, size
|
|||||||
|
|
||||||
func resolveLayers(ctx context.Context, store content.Store, layerFiles []string, blobs map[string]ocispec.Descriptor, compress bool) ([]ocispec.Descriptor, error) {
|
func resolveLayers(ctx context.Context, store content.Store, layerFiles []string, blobs map[string]ocispec.Descriptor, compress bool) ([]ocispec.Descriptor, error) {
|
||||||
layers := make([]ocispec.Descriptor, len(layerFiles))
|
layers := make([]ocispec.Descriptor, len(layerFiles))
|
||||||
|
filters := make([]string, len(layerFiles))
|
||||||
descs := map[digest.Digest]*ocispec.Descriptor{}
|
descs := map[digest.Digest]*ocispec.Descriptor{}
|
||||||
filters := []string{}
|
|
||||||
for i, f := range layerFiles {
|
for i, f := range layerFiles {
|
||||||
desc, ok := blobs[f]
|
desc, ok := blobs[f]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -265,7 +265,7 @@ func resolveLayers(ctx context.Context, store content.Store, layerFiles []string
|
|||||||
}
|
}
|
||||||
layers[i] = desc
|
layers[i] = desc
|
||||||
descs[desc.Digest] = &layers[i]
|
descs[desc.Digest] = &layers[i]
|
||||||
filters = append(filters, fmt.Sprintf("labels.\"%s\"==%s", labels.LabelUncompressed, desc.Digest.String()))
|
filters[i] = fmt.Sprintf("labels.\"%s\"==%s", labels.LabelUncompressed, desc.Digest.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
err := store.Walk(ctx, func(info content.Info) error {
|
err := store.Walk(ctx, func(info content.Info) error {
|
||||||
|
@ -64,9 +64,9 @@ func commonContainerToNRI(ctr Container) *nri.Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func containersToNRI(ctrList []Container) []*nri.Container {
|
func containersToNRI(ctrList []Container) []*nri.Container {
|
||||||
ctrs := []*nri.Container{}
|
ctrs := make([]*nri.Container, len(ctrList))
|
||||||
for _, ctr := range ctrList {
|
for i, ctr := range ctrList {
|
||||||
ctrs = append(ctrs, containerToNRI(ctr))
|
ctrs[i] = containerToNRI(ctr)
|
||||||
}
|
}
|
||||||
return ctrs
|
return ctrs
|
||||||
}
|
}
|
||||||
|
@ -1098,9 +1098,9 @@ func getSupplementalGroupsFromPath(root string, filter func(user.Group) bool) ([
|
|||||||
// if there are no additional groups; just return an empty set
|
// if there are no additional groups; just return an empty set
|
||||||
return []uint32{}, nil
|
return []uint32{}, nil
|
||||||
}
|
}
|
||||||
addlGids := []uint32{}
|
addlGids := make([]uint32, len(groups))
|
||||||
for _, grp := range groups {
|
for i, grp := range groups {
|
||||||
addlGids = append(addlGids, uint32(grp.Gid))
|
addlGids[i] = uint32(grp.Gid)
|
||||||
}
|
}
|
||||||
return addlGids, nil
|
return addlGids, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user