Skip to content

Commit 9b6f1dc

Browse files
committed
Use slices.Clone for copying slices
1 parent 48268f8 commit 9b6f1dc

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

group.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package main
22

3-
import "github.com/hansmi/prometheus-lvm-exporter/lvmreport"
3+
import (
4+
"slices"
5+
6+
"github.com/hansmi/prometheus-lvm-exporter/lvmreport"
7+
)
48

59
type group struct {
610
name lvmreport.GroupName
@@ -13,7 +17,7 @@ type group struct {
1317
}
1418

1519
func (r *group) allDescriptors() []*descriptor {
16-
d := append([]*descriptor(nil), r.keyFields...)
20+
d := slices.Clone(r.keyFields)
1721
d = append(d, r.infoFields...)
1822
d = append(d, r.metricFields...)
1923
return d

group_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func checkSingleDescriptor(t *testing.T, g *group, d *descriptor) {
8282
func checkReportFields(t *testing.T, g *group, fields []*descriptor) {
8383
t.Helper()
8484

85-
sortedFields := append([]*descriptor(nil), fields...)
85+
sortedFields := slices.Clone(fields)
8686

8787
slices.SortFunc(sortedFields, func(a, b *descriptor) int {
8888
return strings.Compare(a.fieldName, b.fieldName)

groupcollector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func newGroupCollector(g *group) *groupCollector {
5959
keyLabelNames = append(keyLabelNames, d.metricName)
6060
}
6161

62-
infoLabelNames := append([]string(nil), keyLabelNames...)
62+
infoLabelNames := slices.Clone(keyLabelNames)
6363

6464
for _, d := range g.infoFields {
6565
c.infoFields = append(c.infoFields, d.fieldName)
@@ -103,7 +103,7 @@ func (c *groupCollector) collect(ch chan<- prometheus.Metric, data *lvmreport.Re
103103
keyValues = append(keyValues, row[name])
104104
}
105105

106-
infoValues := append([]string(nil), keyValues...)
106+
infoValues := slices.Clone(keyValues)
107107

108108
for _, name := range c.infoFields {
109109
infoValues = append(infoValues, row[name])

lvmreport/command.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"os"
88
"os/exec"
9+
"slices"
910
"strings"
1011

1112
"github.com/kballard/go-shellquote"
@@ -32,7 +33,7 @@ func NewCommand(args []string) *Command {
3233
}
3334

3435
func (c *Command) completeArgs() []string {
35-
args := append([]string(nil), c.args...)
36+
args := slices.Clone(c.args)
3637

3738
args = append(args,
3839
"fullreport",

0 commit comments

Comments
 (0)