From 2c382f5e24e87aa7180c92c895741028da21b0e9 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 23 Dec 2022 12:40:22 +0000 Subject: [PATCH] promql: extract function to initialize LabelBuilder Signed-off-by: Bryan Boreham --- promql/engine.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/promql/engine.go b/promql/engine.go index 0455779a4..a6fc29540 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -1032,6 +1032,14 @@ type EvalNodeHelper struct { resultMetric map[string]labels.Labels } +func (enh *EvalNodeHelper) resetBuilder(lbls labels.Labels) { + if enh.lb == nil { + enh.lb = labels.NewBuilder(lbls) + } else { + enh.lb.Reset(lbls) + } +} + // DropMetricName is a cached version of DropMetricName. func (enh *EvalNodeHelper) DropMetricName(l labels.Labels) labels.Labels { if enh.Dmn == nil { @@ -2152,12 +2160,7 @@ func resultMetric(lhs, rhs labels.Labels, op parser.ItemType, matching *parser.V enh.resultMetric = make(map[string]labels.Labels, len(enh.Out)) } - if enh.lb == nil { - enh.lb = labels.NewBuilder(lhs) - } else { - enh.lb.Reset(lhs) - } - + enh.resetBuilder(lhs) buf := bytes.NewBuffer(enh.lblResultBuf[:0]) enh.lblBuf = lhs.Bytes(enh.lblBuf) buf.Write(enh.lblBuf)