*: replace uses of uniq with slices.Compact (#3821)

This commit is contained in:
Alessandro Arzilli 2024-10-01 19:16:49 +02:00 committed by GitHub
parent 8c645a32d7
commit a3d7712752
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 35 deletions

@ -16,6 +16,7 @@ import (
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"slices"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@ -2297,7 +2298,7 @@ func loadBinaryInfoGoRuntimeCommon(bi *BinaryInfo, image *Image, cu *compileUnit
bi.Sources = append(bi.Sources, f) bi.Sources = append(bi.Sources, f)
} }
sort.Strings(bi.Sources) sort.Strings(bi.Sources)
bi.Sources = uniq(bi.Sources) bi.Sources = slices.Compact(bi.Sources)
return nil return nil
} }
@ -2536,7 +2537,7 @@ func (bi *BinaryInfo) loadDebugInfoMaps(image *Image, debugInfoBytes, debugLineB
} }
} }
sort.Strings(bi.Sources) sort.Strings(bi.Sources)
bi.Sources = uniq(bi.Sources) bi.Sources = slices.Compact(bi.Sources)
if cont != nil { if cont != nil {
cont() cont()
@ -2860,21 +2861,6 @@ func (bi *BinaryInfo) loadDebugInfoMapsInlinedCalls(ctxt *loadDebugInfoMapsConte
} }
} }
func uniq(s []string) []string {
if len(s) == 0 {
return s
}
src, dst := 1, 1
for src < len(s) {
if s[src] != s[dst-1] {
s[dst] = s[src]
dst++
}
src++
}
return s[:dst]
}
func (bi *BinaryInfo) expandPackagesInType(expr ast.Expr) { func (bi *BinaryInfo) expandPackagesInType(expr ast.Expr) {
switch e := expr.(type) { switch e := expr.(type) {
case *ast.ArrayType: case *ast.ArrayType:

@ -15,6 +15,7 @@ import (
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime" "runtime"
"slices"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@ -1440,25 +1441,10 @@ func (d *Debugger) Sources(filter string) ([]string, error) {
} }
} }
sort.Strings(files) sort.Strings(files)
files = uniq(files) files = slices.Compact(files)
return files, nil return files, nil
} }
func uniq(s []string) []string {
if len(s) == 0 {
return s
}
src, dst := 1, 1
for src < len(s) {
if s[src] != s[dst-1] {
s[dst] = s[src]
dst++
}
src++
}
return s[:dst]
}
// Functions returns a list of functions in the target process. // Functions returns a list of functions in the target process.
func (d *Debugger) Functions(filter string, followCalls int) ([]string, error) { func (d *Debugger) Functions(filter string, followCalls int) ([]string, error) {
d.targetMutex.Lock() d.targetMutex.Lock()
@ -1487,7 +1473,7 @@ func (d *Debugger) Functions(filter string, followCalls int) ([]string, error) {
} }
} }
sort.Strings(funcs) sort.Strings(funcs)
funcs = uniq(funcs) funcs = slices.Compact(funcs)
return funcs, nil return funcs, nil
} }
@ -1578,7 +1564,7 @@ func (d *Debugger) Types(filter string) ([]string, error) {
} }
} }
sort.Strings(r) sort.Strings(r)
r = uniq(r) r = slices.Compact(r)
return r, nil return r, nil
} }