Avoid potential reallocs by pre-sizing some slices
There's a couple spots where we know exactly how large the destination buffer should be, so pre-size these to avoid any reallocs to a higher capacity. Signed-off-by: Danny Canter <danny@dcantah.dev>
This commit is contained in:
		| @@ -268,9 +268,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 | ||||
| } | ||||
| @@ -513,9 +513,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...) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Danny Canter
					Danny Canter