Skip to content

Commit

Permalink
internal/vuln: use slices.Compact
Browse files Browse the repository at this point in the history
Remove our copy with a call to the stdlib function.

Change-Id: I2964ea3acdf51459a3d09fd79417da5036b14a54
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/636516
LUCI-TryBot-Result: Go LUCI <[email protected]>
kokoro-CI: kokoro <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
  • Loading branch information
jba committed Dec 16, 2024
1 parent 0a279fb commit b2e5c1d
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions internal/vuln/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"fmt"
"path"
"slices"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -284,31 +285,11 @@ func (c *Client) ByPackagePrefix(ctx context.Context, prefix string) (_ []*osv.E
}
sortIDs(ids)
// Remove any duplicates.
ids = slicesCompact(ids)
ids = slices.Compact(ids)

return c.byIDsFilter(ctx, ids, entryMatch)
}

// slicesCompact is a copy of slices.Compact.
// TODO: remove this function and replace its usage with
// slices.Compact once we can depend on it being present
// in the standard library of the previous two Go versions.
func slicesCompact[S ~[]E, E comparable](s S) S {
if len(s) < 2 {
return s
}
i := 1
for k := 1; k < len(s); k++ {
if s[k] != s[k-1] {
if i != k {
s[i] = s[k]
}
i++
}
}
return s[:i]
}

func (c *Client) byIDsFilter(ctx context.Context, ids []string, filter func(*osv.Entry) bool) (_ []*osv.Entry, err error) {
entries, err := c.byIDs(ctx, ids)
if err != nil {
Expand Down

0 comments on commit b2e5c1d

Please sign in to comment.