Merge pull request #121846 from Iceber/sets_keyset

Set the initial length of set[T] in sets.KeySet
This commit is contained in:
Kubernetes Prow Robot 2023-12-13 23:55:19 +01:00 committed by GitHub
commit b0ccc04e47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,7 +38,7 @@ func New[T comparable](items ...T) Set[T] {
// KeySet creates a Set from a keys of a map[comparable](? extends interface{}).
// If the value passed in is not actually a map, this will panic.
func KeySet[T comparable, V any](theMap map[T]V) Set[T] {
ret := Set[T]{}
ret := make(Set[T], len(theMap))
for keyValue := range theMap {
ret.Insert(keyValue)
}