Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
Specify the map size hint. Refactor the map to use struct instead of
bool.
  • Loading branch information
patrickmscott committed Oct 29, 2024
1 parent 8a60b63 commit b2abf0d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
8 changes: 4 additions & 4 deletions language/go/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ import (

var minimumRulesGoVersion = version.Version{0, 29, 0}

type tagSet map[string]bool
type tagSet map[string]struct{}

func (ts tagSet) clone() tagSet {
c := make(tagSet)
c := make(tagSet, len(ts))
for k, v := range ts {
c[k] = v
}
Expand Down Expand Up @@ -189,7 +189,7 @@ func newGoConfig() *goConfig {
goGrpcCompilers: defaultGoGrpcCompilers,
goGenerateProto: true,
genericTags: []tagSet{
{"gc": true},
{"gc": struct{}{}},
},
}
return gc
Expand Down Expand Up @@ -224,7 +224,7 @@ func (gc *goConfig) setBuildTags(tags string) error {
var newSets []tagSet
for _, ts := range gc.genericTags {
c := ts.clone()
c[t] = true
c[t] = struct{}{}
newSets = append(newSets, c)
}
gc.genericTags = append(gc.genericTags, newSets...)
Expand Down
16 changes: 12 additions & 4 deletions language/go/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,19 @@ func testConfig(t *testing.T, args ...string) (*config.Config, []language.Langua
return c, langs, cexts
}

func newTagSet(tags ...string) tagSet {
ts := make(tagSet)
for _, t := range tags {
ts[t] = struct{}{}
}
return ts
}

var expectedBuildTags = []tagSet{
{"gc": true},
{"gc": true, "foo": true},
{"gc": true, "bar": true},
{"gc": true, "foo": true, "bar": true},
newTagSet("gc"),
newTagSet("gc", "foo"),
newTagSet("gc", "bar"),
newTagSet("gc", "foo", "bar"),
}

func TestCommandLine(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion language/go/fileinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ func checkConstraints(c *config.Config, os, arch, osSuffix, archSuffix string, t
return arch == tag
}

return ts[tag]
_, ok := ts[tag]
return ok
}

for _, ts := range goConf.genericTags {
Expand Down

0 comments on commit b2abf0d

Please sign in to comment.