Skip to content

Commit

Permalink
Merge pull request #1170 from tych0/fix-slice-mutation
Browse files Browse the repository at this point in the history
*Slice: don't mutate the underlying default value
  • Loading branch information
rliebz committed Aug 26, 2020
2 parents fe4a429 + 7c493f6 commit af7fa3d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion flag_int64_slice.go
Expand Up @@ -171,7 +171,9 @@ func lookupInt64Slice(name string, set *flag.FlagSet) []int64 {
func removeFromInt64Slice(slice []int64, val int64) []int64 {
for i, v := range slice {
if v == val {
return append(slice[:i], slice[i+1:]...)
ret := append([]int64{}, slice[:i]...)
ret = append(ret, slice[i+1:]...)
return ret
}
}
return slice
Expand Down
4 changes: 3 additions & 1 deletion flag_int_slice.go
Expand Up @@ -170,7 +170,9 @@ func lookupIntSlice(name string, set *flag.FlagSet) []int {
func removeFromIntSlice(slice []int, val int) []int {
for i, v := range slice {
if v == val {
return append(slice[:i], slice[i+1:]...)
ret := append([]int{}, slice[:i]...)
ret = append(ret, slice[i+1:]...)
return ret
}
}
return slice
Expand Down
4 changes: 3 additions & 1 deletion flag_string_slice.go
Expand Up @@ -156,7 +156,9 @@ func lookupStringSlice(name string, set *flag.FlagSet) []string {
func removeFromStringSlice(slice []string, val string) []string {
for i, v := range slice {
if v == val {
return append(slice[:i], slice[i+1:]...)
ret := append([]string{}, slice[:i]...)
ret = append(ret, slice[i+1:]...)
return ret
}
}
return slice
Expand Down

0 comments on commit af7fa3d

Please sign in to comment.