From 30297f0d9bd4a7c2179191c9896989161fb1aa5c Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 6 Mar 2023 16:29:21 +0000 Subject: [PATCH] stringlabels: size buffer for added labels This makes the buffer the correct size for the common case that labels have only been added. It will be too large for the case that labels are changed, but the current buffer resize logic in `appendLabelTo` doubles the buffer, so a small over-estimate is better. Signed-off-by: Bryan Boreham --- model/labels/labels_string.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/model/labels/labels_string.go b/model/labels/labels_string.go index e912882fe..57d8236a5 100644 --- a/model/labels/labels_string.go +++ b/model/labels/labels_string.go @@ -599,7 +599,8 @@ func (b *Builder) Labels(res Labels) Labels { sort.Strings(b.del) a, d := 0, 0 - buf := make([]byte, 0, len(b.base.data)) // TODO: see if we can re-use the buffer from res. + bufSize := len(b.base.data) + labelsSize(b.add) + buf := make([]byte, 0, bufSize) // TODO: see if we can re-use the buffer from res. for pos := 0; pos < len(b.base.data); { oldPos := pos var lName string