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 <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2023-03-06 16:29:21 +00:00
parent d437f0bb6b
commit 30297f0d9b
1 changed files with 2 additions and 1 deletions

View File

@ -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