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:
Aliaksandr Valialkin 2024-04-20 21:00:00 +02:00
parent 3e728c41f6
commit 7531e9084a
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
4 changed files with 7 additions and 27 deletions

View file

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

View file

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

View file

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

View file

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