Use Set[Type] instead of map[Type]bool/struct{}. (#26804)

This commit is contained in:
KN4CK3R 2023-08-30 08:55:25 +02:00 committed by GitHub
parent 815d267c80
commit 5315153059
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 48 deletions

View file

@ -9,6 +9,7 @@ import (
"strings"
"code.gitea.io/gitea/models/perm"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
)
@ -318,14 +319,13 @@ var (
// FindUnitTypes give the unit key names and return valid unique units and invalid keys
func FindUnitTypes(nameKeys ...string) (res []Type, invalidKeys []string) {
m := map[Type]struct{}{}
m := make(container.Set[Type])
for _, key := range nameKeys {
t := TypeFromKey(key)
if t == TypeInvalid {
invalidKeys = append(invalidKeys, key)
} else if _, ok := m[t]; !ok {
} else if m.Add(t) {
res = append(res, t)
m[t] = struct{}{}
}
}
return res, invalidKeys