From 27f865ec49132f3c0994e76d52616ea70300ba64 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Wed, 15 Dec 2021 16:56:33 +0100 Subject: [PATCH] histograms: avoid initialization tracking in reverseFloatBucketIterator Signed-off-by: beorn7 --- model/histogram/float_histogram.go | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/model/histogram/float_histogram.go b/model/histogram/float_histogram.go index 0493984a1..a3bfc6bb7 100644 --- a/model/histogram/float_histogram.go +++ b/model/histogram/float_histogram.go @@ -584,8 +584,6 @@ type reverseFloatBucketIterator struct { currCount float64 // Count in the current bucket. currIdx int32 // The actual bucket index. currLower, currUpper float64 // Limits of the current bucket. - - initiated bool } func newReverseFloatBucketIterator(h *FloatHistogram, positive bool) *reverseFloatBucketIterator { @@ -597,24 +595,21 @@ func newReverseFloatBucketIterator(h *FloatHistogram, positive bool) *reverseFlo r.spans = h.NegativeSpans r.buckets = h.NegativeBuckets } + + r.spansIdx = len(r.spans) - 1 + r.bucketsIdx = len(r.buckets) - 1 + if r.spansIdx >= 0 { + r.idxInSpan = int32(r.spans[r.spansIdx].Length) - 1 + } + r.currIdx = 0 + for _, s := range r.spans { + r.currIdx += s.Offset + int32(s.Length) + } + return r } func (r *reverseFloatBucketIterator) Next() bool { - if !r.initiated { - r.initiated = true - r.spansIdx = len(r.spans) - 1 - r.bucketsIdx = len(r.buckets) - 1 - if r.spansIdx >= 0 { - r.idxInSpan = int32(r.spans[r.spansIdx].Length) - 1 - } - - r.currIdx = 0 - for _, s := range r.spans { - r.currIdx += s.Offset + int32(s.Length) - } - } - r.currIdx-- if r.bucketsIdx < 0 { return false