Skip to content

Commit

Permalink
*: replace uses of uniq with slices.Compact (go-delve#3821)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarzilli authored Oct 1, 2024
1 parent 8c645a3 commit a3d7712
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 35 deletions.
20 changes: 3 additions & 17 deletions pkg/proc/bininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"io"
"os"
"path/filepath"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 4 additions & 18 deletions service/debugger/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit a3d7712

Please sign in to comment.