mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
all: use clear() built-in Go function for clearing []prompbmarshal.TimeSeries and []prompbmarshal.Label slices
This makes the code a bit clear.
This commit is contained in:
parent
3e728c41f6
commit
7531e9084a
4 changed files with 7 additions and 27 deletions
|
@ -21,13 +21,7 @@ type PushCtx struct {
|
|||
|
||||
// Reset resets ctx.
|
||||
func (ctx *PushCtx) Reset() {
|
||||
tss := ctx.WriteRequest.Timeseries
|
||||
for i := range tss {
|
||||
ts := &tss[i]
|
||||
ts.Labels = nil
|
||||
ts.Samples = nil
|
||||
}
|
||||
ctx.WriteRequest.Timeseries = ctx.WriteRequest.Timeseries[:0]
|
||||
ctx.WriteRequest.Reset()
|
||||
|
||||
promrelabel.CleanLabels(ctx.Labels)
|
||||
ctx.Labels = ctx.Labels[:0]
|
||||
|
|
|
@ -122,11 +122,7 @@ func (wr *writeRequest) reset() {
|
|||
|
||||
wr.wr.Timeseries = nil
|
||||
|
||||
for i := range wr.tss {
|
||||
ts := &wr.tss[i]
|
||||
ts.Labels = nil
|
||||
ts.Samples = nil
|
||||
}
|
||||
clear(wr.tss)
|
||||
wr.tss = wr.tss[:0]
|
||||
|
||||
promrelabel.CleanLabels(wr.labels)
|
||||
|
|
|
@ -680,11 +680,8 @@ func (wc *writeRequestCtx) reset() {
|
|||
func (wc *writeRequestCtx) resetNoRows() {
|
||||
wc.writeRequest.Reset()
|
||||
|
||||
labels := wc.labels
|
||||
for i := range labels {
|
||||
labels[i] = prompbmarshal.Label{}
|
||||
}
|
||||
wc.labels = labels[:0]
|
||||
clear(wc.labels)
|
||||
wc.labels = wc.labels[:0]
|
||||
|
||||
wc.samples = wc.samples[:0]
|
||||
}
|
||||
|
|
|
@ -238,13 +238,8 @@ type writeContext struct {
|
|||
func (wr *writeContext) reset() {
|
||||
wr.bb.Reset()
|
||||
|
||||
tss := wr.tss
|
||||
for i := range tss {
|
||||
ts := &tss[i]
|
||||
ts.Labels = nil
|
||||
ts.Samples = nil
|
||||
}
|
||||
wr.tss = tss[:0]
|
||||
clear(wr.tss)
|
||||
wr.tss = wr.tss[:0]
|
||||
|
||||
wr.baseLabels = resetLabels(wr.baseLabels)
|
||||
wr.pointLabels = resetLabels(wr.pointLabels)
|
||||
|
@ -254,9 +249,7 @@ func (wr *writeContext) reset() {
|
|||
}
|
||||
|
||||
func resetLabels(labels []prompbmarshal.Label) []prompbmarshal.Label {
|
||||
for i := range labels {
|
||||
labels[i] = prompbmarshal.Label{}
|
||||
}
|
||||
clear(labels)
|
||||
return labels[:0]
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue