From e5964849269d64a2912689315b52b0c2ac9f40ee Mon Sep 17 00:00:00 2001 From: aarzilli Date: Tue, 1 Oct 2024 18:48:43 +0200 Subject: [PATCH] *: replace uses of uniq with slices.Compact --- pkg/proc/bininfo.go | 20 +++----------------- service/debugger/debugger.go | 22 ++++------------------ 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/pkg/proc/bininfo.go b/pkg/proc/bininfo.go index 6c03ab59c..3f999946c 100644 --- a/pkg/proc/bininfo.go +++ b/pkg/proc/bininfo.go @@ -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: diff --git a/service/debugger/debugger.go b/service/debugger/debugger.go index a63879366..99476ad4c 100644 --- a/service/debugger/debugger.go +++ b/service/debugger/debugger.go @@ -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 }