Skip to content

Commit 373bceb

Browse files
ringbuffer: dont allocate new steprange on reset (#640)
Signed-off-by: Michael Hoffmann <[email protected]>
1 parent 1822755 commit 373bceb

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

ringbuffer/overtime.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,14 @@ func (r *CountOverTimeBuffer) Reset(mint int64, evalt int64) {
113113
nextMint = r.stepRanges[lastSample].mint + r.step
114114
nextMaxt = r.stepRanges[lastSample].maxt + r.step
115115
)
116+
117+
nextStepRange := r.stepRanges[0]
116118
copy(r.stepRanges, r.stepRanges[1:])
117-
r.stepRanges[lastSample] = stepRange{mint: nextMint, maxt: nextMaxt}
119+
r.stepRanges[lastSample] = nextStepRange
120+
r.stepRanges[lastSample].mint = nextMint
121+
r.stepRanges[lastSample].maxt = nextMaxt
122+
r.stepRanges[lastSample].sampleCount = 0
123+
r.stepRanges[lastSample].numSamples = 0
118124

119125
copy(r.resultCounts, r.resultCounts[1:])
120126
r.resultCounts[lastSample] = 0

ringbuffer/rate.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,14 @@ func (r *RateBuffer) Reset(mint int64, evalt int64) {
162162
nextMint = r.stepRanges[lastSample].mint + r.step
163163
nextMaxt = r.stepRanges[lastSample].maxt + r.step
164164
)
165+
166+
nextStepRange := r.stepRanges[0]
165167
copy(r.stepRanges, r.stepRanges[1:])
166-
r.stepRanges[lastSample] = stepRange{mint: nextMint, maxt: nextMaxt}
168+
r.stepRanges[lastSample] = nextStepRange
169+
r.stepRanges[lastSample].mint = nextMint
170+
r.stepRanges[lastSample].maxt = nextMaxt
171+
r.stepRanges[lastSample].sampleCount = 0
172+
r.stepRanges[lastSample].numSamples = 0
167173

168174
nextSample := r.firstSamples[0]
169175
copy(r.firstSamples, r.firstSamples[1:])

0 commit comments

Comments
 (0)