Merge pull request #10488 from dcantah/avoid-realloc

Avoid potential reallocs by pre-sizing some slices
This commit is contained in:
Samuel Karp
2024-07-22 05:39:19 +00:00
committed by GitHub
5 changed files with 17 additions and 17 deletions

View File

@@ -274,9 +274,9 @@ func (c *Client) Containers(ctx context.Context, filters ...string) ([]Container
if err != nil {
return nil, err
}
var out []Container
for _, container := range r {
out = append(out, containerFromRecord(c, container))
out := make([]Container, len(r))
for i, container := range r {
out[i] = containerFromRecord(c, container)
}
return out, nil
}
@@ -519,9 +519,9 @@ func (c *Client) Restore(ctx context.Context, id string, checkpoint Image, opts
}
defer done(ctx)
copts := []NewContainerOpts{}
for _, o := range opts {
copts = append(copts, o(ctx, id, c, checkpoint, index))
copts := make([]NewContainerOpts, len(opts))
for i, o := range opts {
copts[i] = o(ctx, id, c, checkpoint, index)
}
ctr, err := c.NewContainer(ctx, id, copts...)