From d1af84f6ee52398cf4bf76f490466a687d03e130 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 24 Nov 2023 12:17:28 +0000 Subject: [PATCH] Labels: move Builder and Reset out of common New internstrings implementation is different. Signed-off-by: Bryan Boreham --- model/labels/labels.go | 19 +++++++++++++++++++ model/labels/labels_common.go | 19 ------------------- model/labels/labels_stringlabels.go | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/model/labels/labels.go b/model/labels/labels.go index b6663dad2..9e74b3d31 100644 --- a/model/labels/labels.go +++ b/model/labels/labels.go @@ -371,6 +371,25 @@ func (ls Labels) ReleaseStrings(release func(string)) { } } +// Builder allows modifying Labels. +type Builder struct { + base Labels + del []string + add []Label +} + +// Reset clears all current state for the builder. +func (b *Builder) Reset(base Labels) { + b.base = base + b.del = b.del[:0] + b.add = b.add[:0] + b.base.Range(func(l Label) { + if l.Value == "" { + b.del = append(b.del, l.Name) + } + }) +} + // Labels returns the labels from the builder. // If no modifications were made, the original labels are returned. func (b *Builder) Labels() Labels { diff --git a/model/labels/labels_common.go b/model/labels/labels_common.go index 2a722b84c..e51001e7d 100644 --- a/model/labels/labels_common.go +++ b/model/labels/labels_common.go @@ -123,13 +123,6 @@ func FromMap(m map[string]string) Labels { return New(l...) } -// Builder allows modifying Labels. -type Builder struct { - base Labels - del []string - add []Label -} - // NewBuilder returns a new LabelsBuilder. func NewBuilder(base Labels) *Builder { b := &Builder{ @@ -140,18 +133,6 @@ func NewBuilder(base Labels) *Builder { return b } -// Reset clears all current state for the builder. -func (b *Builder) Reset(base Labels) { - b.base = base - b.del = b.del[:0] - b.add = b.add[:0] - b.base.Range(func(l Label) { - if l.Value == "" { - b.del = append(b.del, l.Name) - } - }) -} - // Del deletes the label of the given name. func (b *Builder) Del(ns ...string) *Builder { for _, n := range ns { diff --git a/model/labels/labels_stringlabels.go b/model/labels/labels_stringlabels.go index 3e0488bd0..b84964776 100644 --- a/model/labels/labels_stringlabels.go +++ b/model/labels/labels_stringlabels.go @@ -458,6 +458,25 @@ func (ls *Labels) InternStrings(intern func(string) string) { func (ls Labels) ReleaseStrings(release func(string)) { } +// Builder allows modifying Labels. +type Builder struct { + base Labels + del []string + add []Label +} + +// Reset clears all current state for the builder. +func (b *Builder) Reset(base Labels) { + b.base = base + b.del = b.del[:0] + b.add = b.add[:0] + b.base.Range(func(l Label) { + if l.Value == "" { + b.del = append(b.del, l.Name) + } + }) +} + // Labels returns the labels from the builder. // If no modifications were made, the original labels are returned. func (b *Builder) Labels() Labels {