Skip to content

Commit d8c70ff

Browse files
pre-allocate slices
Signed-off-by: warnar boekkooi <wboekkooi@impossiblecloud.com>
1 parent 3d3db39 commit d8c70ff

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

model/metric.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ func EscapeMetricFamily(v *dto.MetricFamily, scheme EscapingScheme) *dto.MetricF
355355
} else {
356356
out.Name = proto.String(EscapeName(v.GetName(), scheme))
357357
}
358+
if v.Metric != nil {
359+
out.Metric = make([]*dto.Metric, 0, len(v.Metric))
360+
}
358361
for _, m := range v.Metric {
359362
if !metricNeedsEscaping(m) {
360363
out.Metric = append(out.Metric, m)
@@ -369,7 +372,9 @@ func EscapeMetricFamily(v *dto.MetricFamily, scheme EscapingScheme) *dto.MetricF
369372
Histogram: m.Histogram,
370373
TimestampMs: m.TimestampMs,
371374
}
372-
375+
if m.Label != nil {
376+
escaped.Label = make([]*dto.LabelPair, 0, len(m.Label))
377+
}
373378
for _, l := range m.Label {
374379
if l.GetName() == MetricNameLabel {
375380
if l.Value == nil || IsValidLegacyMetricName(l.GetValue()) {

0 commit comments

Comments
 (0)