Skip to content

Commit 30cc364

Browse files
committed
internal/vuln: remove the dependency on golang.org/x/exp
It's used for slices.Compact. This change makes a copy of that function, which should be removed once we can depend on it being present in the standard library. For golang/go#61399 Change-Id: I3fcd49a3d4cf1a40c402ca137efa9a16929c2cc1 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/514519 kokoro-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Michael Matloob <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent 4434dd5 commit 30cc364

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ require (
3434
github.com/yuin/goldmark v1.4.13
3535
github.com/yuin/goldmark-emoji v1.0.1
3636
go.opencensus.io v0.23.0
37-
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53
3837
golang.org/x/mod v0.8.0
3938
golang.org/x/net v0.13.0
4039
golang.org/x/sync v0.1.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,8 +1108,6 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
11081108
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
11091109
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
11101110
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
1111-
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 h1:5llv2sWeaMSnA3w2kS57ouQQ4pudlXrR0dCgw51QK9o=
1112-
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
11131111
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
11141112
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
11151113
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=

internal/vuln/client.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"sort"
1313
"strings"
1414

15-
"golang.org/x/exp/slices"
1615
"golang.org/x/pkgsite/internal/derrors"
1716
"golang.org/x/pkgsite/internal/osv"
1817
"golang.org/x/pkgsite/internal/stdlib"
@@ -299,11 +298,31 @@ func (c *Client) ByPackagePrefix(ctx context.Context, prefix string) (_ []*osv.E
299298
}
300299
sortIDs(ids)
301300
// Remove any duplicates.
302-
ids = slices.Compact(ids)
301+
ids = slicesCompact(ids)
303302

304303
return c.byIDsFilter(ctx, ids, entryMatch)
305304
}
306305

306+
// slicesCompact is a copy of slices.Compact.
307+
// TODO: remove this function and replace its usage with
308+
// slices.Compact once we can depend on it being present
309+
// in the standard library of the previous two Go versions.
310+
func slicesCompact[S ~[]E, E comparable](s S) S {
311+
if len(s) < 2 {
312+
return s
313+
}
314+
i := 1
315+
for k := 1; k < len(s); k++ {
316+
if s[k] != s[k-1] {
317+
if i != k {
318+
s[i] = s[k]
319+
}
320+
i++
321+
}
322+
}
323+
return s[:i]
324+
}
325+
307326
func (c *Client) byIDsFilter(ctx context.Context, ids []string, filter func(*osv.Entry) bool) (_ []*osv.Entry, err error) {
308327
entries, err := c.byIDs(ctx, ids)
309328
if err != nil {

0 commit comments

Comments
 (0)