From 009d9dd9a7f4444a22ac8bb74ea2e380d9ecb5ce Mon Sep 17 00:00:00 2001 From: guangwu Date: Sun, 3 Dec 2023 07:06:54 +0800 Subject: [PATCH] chore: slice loop replace (#688) * chore: slice loop replace Signed-off-by: guoguangwu * chore: use copy instead of a loop Signed-off-by: guoguangwu --------- Signed-off-by: guoguangwu --- pkg/backends/healthcheck/options/options.go | 4 +--- pkg/proxy/headers/result_header.go | 4 +--- pkg/timeseries/timerangequery.go | 8 ++------ 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/pkg/backends/healthcheck/options/options.go b/pkg/backends/healthcheck/options/options.go index 3fe5bad38..803033f40 100644 --- a/pkg/backends/healthcheck/options/options.go +++ b/pkg/backends/healthcheck/options/options.go @@ -116,9 +116,7 @@ func (o *Options) Clone() *Options { } if len(o.ExpectedCodes) > 0 { c.ExpectedCodes = make([]int, len(o.ExpectedCodes)) - for i, v := range o.ExpectedCodes { - c.ExpectedCodes[i] = v - } + copy(c.ExpectedCodes, o.ExpectedCodes) } c.md = o.md c.hasExpectedBody = o.hasExpectedBody diff --git a/pkg/proxy/headers/result_header.go b/pkg/proxy/headers/result_header.go index 6981378c1..716313226 100644 --- a/pkg/proxy/headers/result_header.go +++ b/pkg/proxy/headers/result_header.go @@ -92,9 +92,7 @@ func MergeResultHeaderVals(h1, h2 string) string { if len(r1.Fetched) == 0 { r1.Fetched = r2.Fetched } else { - for _, extent := range r2.Fetched { - r1.Fetched = append(r1.Fetched, extent) - } + r1.Fetched = append(r1.Fetched, r2.Fetched...) r1.Fetched = r1.Fetched.Compress(0) } diff --git a/pkg/timeseries/timerangequery.go b/pkg/timeseries/timerangequery.go index 647b3c5a4..bbeecb7d9 100644 --- a/pkg/timeseries/timerangequery.go +++ b/pkg/timeseries/timerangequery.go @@ -71,16 +71,12 @@ func (trq *TimeRangeQuery) Clone() *TimeRangeQuery { if trq.TagFieldDefintions != nil { t.TagFieldDefintions = make([]FieldDefinition, len(trq.TagFieldDefintions)) - for i, fd := range trq.TagFieldDefintions { - t.TagFieldDefintions[i] = fd - } + copy(t.TagFieldDefintions, trq.TagFieldDefintions) } if trq.ValueFieldDefinitions != nil { t.ValueFieldDefinitions = make([]FieldDefinition, len(trq.ValueFieldDefinitions)) - for i, fd := range trq.ValueFieldDefinitions { - t.ValueFieldDefinitions[i] = fd - } + copy(t.ValueFieldDefinitions, trq.ValueFieldDefinitions) } if trq.TemplateURL != nil {