Skip to content

Commit

Permalink
fix: replace pre-allocating len of the slices with cap
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoutsovasilis committed Jan 11, 2024
1 parent 970f607 commit afbf93d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 2 additions & 4 deletions auditbeat/tracing/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ func NewCPUSetFromFile(path string) (cpus CPUSet, err error) {
func NewCPUSetFromExpression(contents string) (CPUSet, error) {
expressions := strings.Split(contents, ",")

ranges := make([][]int, len(expressions))
rangesIdx := 0
ranges := make([][]int, 0, len(expressions))

var maximum, count int
for _, expr := range expressions {
Expand All @@ -120,8 +119,7 @@ func NewCPUSetFromExpression(contents string) (CPUSet, error) {
maximum = num + 1
}
}
ranges[rangesIdx] = r
rangesIdx++
ranges = append(ranges, r)
}
if maximum == 0 {
return CPUSet{}, nil
Expand Down
7 changes: 3 additions & 4 deletions auditbeat/tracing/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ type dumpDecoder struct {
// - integer of 64bit (u64 / s64).
// - dump consecutive memory.
func NewDumpDecoder(format ProbeFormat) (Decoder, error) {
fields := make([]Field, len(format.Fields))
fieldsIdx := 0
fields := make([]Field, 0, len(format.Fields))

for name, field := range format.Fields {
if strings.Index(name, "arg") != 0 {
continue
Expand All @@ -389,8 +389,7 @@ func NewDumpDecoder(format ProbeFormat) (Decoder, error) {
if field.Size != 8 {
return nil, fmt.Errorf("field '%s' length is not 8", name)
}
fields[fieldsIdx] = field
fieldsIdx++
fields = append(fields, field)
}
if len(fields) == 0 {
return nil, errors.New("no fields to decode")
Expand Down

0 comments on commit afbf93d

Please sign in to comment.