From ea89676c5cee764de171f059cc8998d9b5ebf067 Mon Sep 17 00:00:00 2001 From: Chris Bandy Date: Sat, 25 Jan 2025 16:09:48 -0600 Subject: [PATCH] Replace uniq with slices.Compact --- internal/tracetest/clean.go | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/internal/tracetest/clean.go b/internal/tracetest/clean.go index 6d0362c..77a6152 100644 --- a/internal/tracetest/clean.go +++ b/internal/tracetest/clean.go @@ -7,7 +7,7 @@ import ( "path/filepath" "regexp" "runtime" - "sort" + "slices" "strconv" "strings" ) @@ -81,8 +81,8 @@ func (r fileLineReplacer) Replacements() []string { // Sort the lines in the file, and remove duplicates. // The result will be a slice of unique line numbers. // The index of each line in this slice + 1 will be its new line number. - sort.Ints(fileLines) - fileLines = uniq(fileLines) + slices.Sort(fileLines) + fileLines = slices.Compact(fileLines) for idx, origLine := range fileLines { replaceLine := idx + 1 @@ -93,20 +93,3 @@ func (r fileLineReplacer) Replacements() []string { } return allReplacements } - -// uniq removes contiguous duplicates from v. -// The slice storage is re-used so the original slice -// should not be used after calling this function. -func uniq[T comparable](items []T) []T { - if len(items) == 0 { - return items - } - - newItems := items[:1] - for _, item := range items[1:] { - if item != newItems[len(newItems)-1] { - newItems = append(newItems, item) - } - } - return newItems -}