@@ -19,6 +19,7 @@ package featuregate
1919import (
2020 "flag"
2121 "fmt"
22+ "maps"
2223 "sort"
2324 "strconv"
2425 "strings"
@@ -130,7 +131,7 @@ func NewFeatureGate() *featureGate {
130131// map[string]bool of known keys or returns an error.
131132func (f * featureGate ) Set (value string ) error {
132133 m := make (map [string ]bool )
133- for _ , s := range strings .Split (value , "," ) {
134+ for s := range strings .SplitSeq (value , "," ) {
134135 if len (s ) == 0 {
135136 continue
136137 }
@@ -156,9 +157,8 @@ func (f *featureGate) SetFromMap(m map[string]bool) error {
156157
157158 // Copy existing state
158159 known := map [Feature ]FeatureSpec {}
159- for k , v := range f .known .Load ().(map [Feature ]FeatureSpec ) {
160- known [k ] = v
161- }
160+ maps .Copy (known , f .known .Load ().(map [Feature ]FeatureSpec ))
161+
162162 enabled := map [Feature ]bool {}
163163 for k , v := range f .enabled .Load ().(map [Feature ]bool ) {
164164 enabled [k ] = v
@@ -317,13 +317,9 @@ func (f *featureGate) KnownFeatures() []string {
317317func (f * featureGate ) DeepCopy () MutableFeatureGate {
318318 // Copy existing state.
319319 known := map [Feature ]FeatureSpec {}
320- for k , v := range f .known .Load ().(map [Feature ]FeatureSpec ) {
321- known [k ] = v
322- }
320+ maps .Copy (known , f .known .Load ().(map [Feature ]FeatureSpec ))
323321 enabled := map [Feature ]bool {}
324- for k , v := range f .enabled .Load ().(map [Feature ]bool ) {
325- enabled [k ] = v
326- }
322+ maps .Copy (enabled , f .enabled .Load ().(map [Feature ]bool ))
327323
328324 // Construct a new featureGate around the copied state.
329325 // Note that specialFeatures is treated as immutable by convention,
0 commit comments