Skip to content

Commit

Permalink
fix: update the x/exp package, and updated tagIsLess function (#152)
Browse files Browse the repository at this point in the history
* fix: upgrade the x/exp package, and updated tagIsLess function

* fix the test

* tagIsLess -> tagCompare

* revert dependency versions: attempt to fix subpackage failure
  • Loading branch information
needcaffeine committed Sep 28, 2023
1 parent 16aabc9 commit eec59e2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ require (
github.com/segmentio/objconv v1.0.1
github.com/segmentio/vpcinfo v0.1.10
github.com/stretchr/testify v1.8.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/sync v0.3.0
)

require github.com/davecgh/go-spew v1.1.1 // indirect

require (
github.com/google/go-cmp v0.5.8 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/mdlayher/genetlink v0.0.0-20190313224034-60417448a851 // indirect
github.com/mdlayher/netlink v0.0.0-20190313131330-258ea9dff42c // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/sys v0.12.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand All @@ -29,8 +28,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw=
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
Expand All @@ -39,8 +38,8 @@ golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
Expand Down
15 changes: 12 additions & 3 deletions tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func M(m map[string]string) []Tag {
// TagsAreSorted returns true if the given list of tags is sorted by tag name,
// false otherwise.
func TagsAreSorted(tags []Tag) bool {
return slices.IsSortedFunc(tags, tagIsLess)
return slices.IsSortedFunc(tags, tagCompare)
}

// SortTags sorts and deduplicates tags in-place,
Expand All @@ -46,12 +46,21 @@ func SortTags(tags []Tag) []Tag {
// Stable sort ensures that we have deterministic
// "latest wins" deduplication.
// For 20 or fewer tags, this is as fast as an unstable sort.
slices.SortStableFunc(tags, tagIsLess)
slices.SortStableFunc(tags, tagCompare)

return deduplicateTags(tags)
}

func tagIsLess(a, b Tag) bool { return a.Name < b.Name }
func tagCompare(a, b Tag) int {
switch {
case a.Name < b.Name:
return -1
case a.Name > b.Name:
return +1
}

return 0
}

func deduplicateTags(tags []Tag) []Tag {
var prev string
Expand Down
8 changes: 4 additions & 4 deletions tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func BenchmarkTagsOrder(b *testing.B) {
})
b.Run("slices.IsSortedFunc", func(b *testing.B) {
benchmarkTagsOrder(b, func(tags []Tag) bool {
return slices.IsSortedFunc(tags, tagIsLess)
return slices.IsSortedFunc(tags, tagCompare)
})
})
b.Run("sort.SliceIsSorted", func(b *testing.B) {
Expand All @@ -190,7 +190,7 @@ func BenchmarkTagsOrder(b *testing.B) {

func tagIsLessByIndex(tags []Tag) func(int, int) bool {
return func(i, j int) bool {
return tagIsLess(tags[i], tags[j])
return tagCompare(tags[i], tags[j]) < 0
}
}

Expand Down Expand Up @@ -264,12 +264,12 @@ func benchmark_SortTags(b *testing.B, t0 []Tag) {
})

b.Run("slices.SortFunc", func(b *testing.B) {
fn := func(tags []Tag) { slices.SortFunc(tags, tagIsLess) }
fn := func(tags []Tag) { slices.SortFunc(tags, tagCompare) }
benchmark_SortTags_func(b, t0, fn)
})

b.Run("slices.SortStableFunc", func(b *testing.B) {
fn := func(tags []Tag) { slices.SortStableFunc(tags, tagIsLess) }
fn := func(tags []Tag) { slices.SortStableFunc(tags, tagCompare) }
benchmark_SortTags_func(b, t0, fn)
})

Expand Down

0 comments on commit eec59e2

Please sign in to comment.