histograms: avoid initialization tracking in reverseFloatBucketIterator

Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
beorn7 2021-12-15 16:56:33 +01:00
parent a6acdfe346
commit 27f865ec49
1 changed files with 11 additions and 16 deletions

View File

@ -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