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.
|
// Reset resets ctx.
|
||||||
func (ctx *PushCtx) Reset() {
|
func (ctx *PushCtx) Reset() {
|
||||||
tss := ctx.WriteRequest.Timeseries
|
ctx.WriteRequest.Reset()
|
||||||
for i := range tss {
|
|
||||||
ts := &tss[i]
|
|
||||||
ts.Labels = nil
|
|
||||||
ts.Samples = nil
|
|
||||||
}
|
|
||||||
ctx.WriteRequest.Timeseries = ctx.WriteRequest.Timeseries[:0]
|
|
||||||
|
|
||||||
promrelabel.CleanLabels(ctx.Labels)
|
promrelabel.CleanLabels(ctx.Labels)
|
||||||
ctx.Labels = ctx.Labels[:0]
|
ctx.Labels = ctx.Labels[:0]
|
||||||
|
|
|
@ -122,11 +122,7 @@ func (wr *writeRequest) reset() {
|
||||||
|
|
||||||
wr.wr.Timeseries = nil
|
wr.wr.Timeseries = nil
|
||||||
|
|
||||||
for i := range wr.tss {
|
clear(wr.tss)
|
||||||
ts := &wr.tss[i]
|
|
||||||
ts.Labels = nil
|
|
||||||
ts.Samples = nil
|
|
||||||
}
|
|
||||||
wr.tss = wr.tss[:0]
|
wr.tss = wr.tss[:0]
|
||||||
|
|
||||||
promrelabel.CleanLabels(wr.labels)
|
promrelabel.CleanLabels(wr.labels)
|
||||||
|
|
|
@ -680,11 +680,8 @@ func (wc *writeRequestCtx) reset() {
|
||||||
func (wc *writeRequestCtx) resetNoRows() {
|
func (wc *writeRequestCtx) resetNoRows() {
|
||||||
wc.writeRequest.Reset()
|
wc.writeRequest.Reset()
|
||||||
|
|
||||||
labels := wc.labels
|
clear(wc.labels)
|
||||||
for i := range labels {
|
wc.labels = wc.labels[:0]
|
||||||
labels[i] = prompbmarshal.Label{}
|
|
||||||
}
|
|
||||||
wc.labels = labels[:0]
|
|
||||||
|
|
||||||
wc.samples = wc.samples[:0]
|
wc.samples = wc.samples[:0]
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,13 +238,8 @@ type writeContext struct {
|
||||||
func (wr *writeContext) reset() {
|
func (wr *writeContext) reset() {
|
||||||
wr.bb.Reset()
|
wr.bb.Reset()
|
||||||
|
|
||||||
tss := wr.tss
|
clear(wr.tss)
|
||||||
for i := range tss {
|
wr.tss = wr.tss[:0]
|
||||||
ts := &tss[i]
|
|
||||||
ts.Labels = nil
|
|
||||||
ts.Samples = nil
|
|
||||||
}
|
|
||||||
wr.tss = tss[:0]
|
|
||||||
|
|
||||||
wr.baseLabels = resetLabels(wr.baseLabels)
|
wr.baseLabels = resetLabels(wr.baseLabels)
|
||||||
wr.pointLabels = resetLabels(wr.pointLabels)
|
wr.pointLabels = resetLabels(wr.pointLabels)
|
||||||
|
@ -254,9 +249,7 @@ func (wr *writeContext) reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func resetLabels(labels []prompbmarshal.Label) []prompbmarshal.Label {
|
func resetLabels(labels []prompbmarshal.Label) []prompbmarshal.Label {
|
||||||
for i := range labels {
|
clear(labels)
|
||||||
labels[i] = prompbmarshal.Label{}
|
|
||||||
}
|
|
||||||
return labels[:0]
|
return labels[:0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue