Skip to content

Commit

Permalink
Merge pull request #19201 from arturmelanchyk/optimise-mem-alloc
Browse files Browse the repository at this point in the history
flags: optimise memory allocation
  • Loading branch information
ahrtr authored Jan 18, 2025
2 parents 831fa7a + dcbd309 commit 2f37f48
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/flags/selective_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (ss *SelectiveStringValue) Valids() []string {
// valids[0] will be default value. Caller must be sure
// len(valids) != 0 or it will panic.
func NewSelectiveStringValue(valids ...string) *SelectiveStringValue {
vm := make(map[string]struct{})
vm := make(map[string]struct{}, len(valids))
for _, v := range valids {
vm[v] = struct{}{}
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func (ss *SelectiveStringsValue) Valids() []string {
// for which any one of the given strings is a valid value,
// and any other value is an error.
func NewSelectiveStringsValue(valids ...string) *SelectiveStringsValue {
vm := make(map[string]struct{})
vm := make(map[string]struct{}, len(valids))
for _, v := range valids {
vm[v] = struct{}{}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/flags/unique_strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ type UniqueStringsValue struct {
// Implements "flag.Value" interface.
// The values are set in order.
func (us *UniqueStringsValue) Set(s string) error {
us.Values = make(map[string]struct{})
for _, v := range strings.Split(s, ",") {
values := strings.Split(s, ",")
us.Values = make(map[string]struct{}, len(values))
for _, v := range values {
us.Values[v] = struct{}{}
}
return nil
Expand Down

0 comments on commit 2f37f48

Please sign in to comment.