*: replace uses of uniq with slices.Compact (#3821)
This commit is contained in:
parent
8c645a32d7
commit
a3d7712752
@ -16,6 +16,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -2297,7 +2298,7 @@ func loadBinaryInfoGoRuntimeCommon(bi *BinaryInfo, image *Image, cu *compileUnit
|
||||
bi.Sources = append(bi.Sources, f)
|
||||
}
|
||||
sort.Strings(bi.Sources)
|
||||
bi.Sources = uniq(bi.Sources)
|
||||
bi.Sources = slices.Compact(bi.Sources)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -2536,7 +2537,7 @@ func (bi *BinaryInfo) loadDebugInfoMaps(image *Image, debugInfoBytes, debugLineB
|
||||
}
|
||||
}
|
||||
sort.Strings(bi.Sources)
|
||||
bi.Sources = uniq(bi.Sources)
|
||||
bi.Sources = slices.Compact(bi.Sources)
|
||||
|
||||
if cont != nil {
|
||||
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) {
|
||||
switch e := expr.(type) {
|
||||
case *ast.ArrayType:
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -1440,25 +1441,10 @@ func (d *Debugger) Sources(filter string) ([]string, error) {
|
||||
}
|
||||
}
|
||||
sort.Strings(files)
|
||||
files = uniq(files)
|
||||
files = slices.Compact(files)
|
||||
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.
|
||||
func (d *Debugger) Functions(filter string, followCalls int) ([]string, error) {
|
||||
d.targetMutex.Lock()
|
||||
@ -1487,7 +1473,7 @@ func (d *Debugger) Functions(filter string, followCalls int) ([]string, error) {
|
||||
}
|
||||
}
|
||||
sort.Strings(funcs)
|
||||
funcs = uniq(funcs)
|
||||
funcs = slices.Compact(funcs)
|
||||
return funcs, nil
|
||||
}
|
||||
|
||||
@ -1578,7 +1564,7 @@ func (d *Debugger) Types(filter string) ([]string, error) {
|
||||
}
|
||||
}
|
||||
sort.Strings(r)
|
||||
r = uniq(r)
|
||||
r = slices.Compact(r)
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user