File tree 1 file changed +9
-6
lines changed
1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -89,7 +89,6 @@ func (sw *sweeper) update() {
89
89
timeMultiplier := float64 (time .Second ) / float64 (tdiff )
90
90
91
91
// Calculate the bandwidth for all active meters.
92
- newLen := len (sw .meters )
93
92
for i , m := range sw .meters [:sw .activeMeters ] {
94
93
total := atomic .LoadUint64 (& m .accumulator )
95
94
diff := total - m .snapshot .Total
@@ -147,8 +146,7 @@ func (sw *sweeper) update() {
147
146
// Reset the rate, keep the total.
148
147
m .registered = false
149
148
m .snapshot .Rate = 0
150
- newLen --
151
- sw .meters [i ] = sw .meters [newLen ]
149
+ sw .meters [i ] = nil
152
150
}
153
151
154
152
// Re-add the total to all the newly active accumulators and set the snapshot to the total.
@@ -162,10 +160,15 @@ func (sw *sweeper) update() {
162
160
m .snapshot .Total = total
163
161
}
164
162
165
- // trim the meter list
166
- for i := newLen ; i < len (sw .meters ); i ++ {
167
- sw .meters [i ] = nil
163
+ // compress and trim the meter list
164
+ var newLen int
165
+ for _ , m := range sw .meters {
166
+ if m != nil {
167
+ sw .meters [newLen ] = m
168
+ newLen ++
169
+ }
168
170
}
171
+
169
172
sw .meters = sw .meters [:newLen ]
170
173
171
174
// Finally, mark all meters still in the list as "active".
You can’t perform that action at this time.
0 commit comments