From 617bee60f19bfae850ffc6386e4be7637a0cb631 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 26 Jun 2022 20:11:53 +0100 Subject: [PATCH] labels: use ScratchBuilder in ReadLabels Instead of relying on being able to append to it like a slice. Signed-off-by: Bryan Boreham --- model/labels/test_utils.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/model/labels/test_utils.go b/model/labels/test_utils.go index a683588d1..05b816882 100644 --- a/model/labels/test_utils.go +++ b/model/labels/test_utils.go @@ -17,7 +17,6 @@ import ( "bufio" "fmt" "os" - "sort" "strings" ) @@ -51,13 +50,14 @@ func ReadLabels(fn string, n int) ([]Labels, error) { defer f.Close() scanner := bufio.NewScanner(f) + b := ScratchBuilder{} var mets []Labels hashes := map[uint64]struct{}{} i := 0 for scanner.Scan() && i < n { - m := make(Labels, 0, 10) + b.Reset() r := strings.NewReplacer("\"", "", "{", "", "}", "") s := r.Replace(scanner.Text()) @@ -65,10 +65,11 @@ func ReadLabels(fn string, n int) ([]Labels, error) { labelChunks := strings.Split(s, ",") for _, labelChunk := range labelChunks { split := strings.Split(labelChunk, ":") - m = append(m, Label{Name: split[0], Value: split[1]}) + b.Add(split[0], split[1]) } // Order of the k/v labels matters, don't assume we'll always receive them already sorted. - sort.Sort(m) + b.Sort() + m := b.Labels() h := m.Hash() if _, ok := hashes[h]; ok {