Add generic set type (#21408)
This PR adds a generic set type to get rid of maps used as sets. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
e84558b093
commit
0e57ff7eee
41 changed files with 328 additions and 324 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/builder"
|
||||
|
@ -62,7 +63,7 @@ func ValidateTopic(topic string) bool {
|
|||
// SanitizeAndValidateTopics sanitizes and checks an array or topics
|
||||
func SanitizeAndValidateTopics(topics []string) (validTopics, invalidTopics []string) {
|
||||
validTopics = make([]string, 0)
|
||||
mValidTopics := make(map[string]struct{})
|
||||
mValidTopics := make(container.Set[string])
|
||||
invalidTopics = make([]string, 0)
|
||||
|
||||
for _, topic := range topics {
|
||||
|
@ -72,12 +73,12 @@ func SanitizeAndValidateTopics(topics []string) (validTopics, invalidTopics []st
|
|||
continue
|
||||
}
|
||||
// ignore same topic twice
|
||||
if _, ok := mValidTopics[topic]; ok {
|
||||
if mValidTopics.Contains(topic) {
|
||||
continue
|
||||
}
|
||||
if ValidateTopic(topic) {
|
||||
validTopics = append(validTopics, topic)
|
||||
mValidTopics[topic] = struct{}{}
|
||||
mValidTopics.Add(topic)
|
||||
} else {
|
||||
invalidTopics = append(invalidTopics, topic)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue