···1212 "path/filepath"
1313 "strings"
14141515+ "code.gitea.io/gitea/modules/container"
1516 "code.gitea.io/gitea/modules/setting"
1617)
1718···58595960 // use old en-US as the base, and copy the new translations to the old locales
6061 enUsOld := inisOld["options/locale/locale_en-US.ini"]
6161- brokenWarned := map[string]bool{}
6262+ brokenWarned := make(container.Set[string])
6263 for path, iniOld := range inisOld {
6364 if iniOld == enUsOld {
6465 continue
···7778 broken := oldStr != "" && strings.Count(oldStr, "%") != strings.Count(newStr, "%")
7879 broken = broken || strings.Contains(oldStr, "\n") || strings.Contains(oldStr, "\n")
7980 if broken {
8080- brokenWarned[secOld.Name()+"."+keyEnUs.Name()] = true
8181+ brokenWarned.Add(secOld.Name() + "." + keyEnUs.Name())
8182 fmt.Println("----")
8283 fmt.Printf("WARNING: skip broken locale: %s , [%s] %s\n", path, secEnUS.Name(), keyEnUs.Name())
8384 fmt.Printf("\told: %s\n", strings.ReplaceAll(oldStr, "\n", "\\n"))
···103104 broken = broken || strings.HasPrefix(str, "`\"")
104105 broken = broken || strings.Count(str, `"`)%2 == 1
105106 broken = broken || strings.Count(str, "`")%2 == 1
106106- if broken && !brokenWarned[sec.Name()+"."+key.Name()] {
107107+ if broken && !brokenWarned.Contains(sec.Name()+"."+key.Name()) {
107108 fmt.Printf("WARNING: found broken locale: %s , [%s] %s\n", path, sec.Name(), key.Name())
108109 fmt.Printf("\tstr: %s\n", strings.ReplaceAll(str, "\n", "\\n"))
109110 fmt.Println("----")
+5-9
build/generate-go-licenses.go
···1515 "regexp"
1616 "sort"
1717 "strings"
1818+1919+ "code.gitea.io/gitea/modules/container"
1820)
19212022// regexp is based on go-license, excluding README and NOTICE
···5557 // yml
5658 //
5759 // It could be removed once we have a better regex.
5858- excludedExt := map[string]bool{
5959- ".gitignore": true,
6060- ".go": true,
6161- ".mod": true,
6262- ".sum": true,
6363- ".toml": true,
6464- ".yml": true,
6565- }
6060+ excludedExt := container.SetOf(".gitignore", ".go", ".mod", ".sum", ".toml", ".yml")
6161+6662 var paths []string
6763 err := filepath.WalkDir(base, func(path string, entry fs.DirEntry, err error) error {
6864 if err != nil {
6965 return err
7066 }
7171- if entry.IsDir() || !licenseRe.MatchString(entry.Name()) || excludedExt[filepath.Ext(entry.Name())] {
6767+ if entry.IsDir() || !licenseRe.MatchString(entry.Name()) || excludedExt.Contains(filepath.Ext(entry.Name())) {
7268 return nil
7369 }
7470 paths = append(paths, path)
+3-3
models/unit/unit.go
···99 "strings"
10101111 "code.gitea.io/gitea/models/perm"
1212+ "code.gitea.io/gitea/modules/container"
1213 "code.gitea.io/gitea/modules/log"
1314 "code.gitea.io/gitea/modules/setting"
1415)
···318319319320// FindUnitTypes give the unit key names and return valid unique units and invalid keys
320321func FindUnitTypes(nameKeys ...string) (res []Type, invalidKeys []string) {
321321- m := map[Type]struct{}{}
322322+ m := make(container.Set[Type])
322323 for _, key := range nameKeys {
323324 t := TypeFromKey(key)
324325 if t == TypeInvalid {
325326 invalidKeys = append(invalidKeys, key)
326326- } else if _, ok := m[t]; !ok {
327327+ } else if m.Add(t) {
327328 res = append(res, t)
328328- m[t] = struct{}{}
329329 }
330330 }
331331 return res, invalidKeys
+7-12
modules/assetfs/layered.go
···1414 "sort"
1515 "time"
16161717+ "code.gitea.io/gitea/modules/container"
1718 "code.gitea.io/gitea/modules/log"
1819 "code.gitea.io/gitea/modules/process"
1920 "code.gitea.io/gitea/modules/util"
···130131// * false: only directories will be returned.
131132// The returned files are sorted by name.
132133func (l *LayeredFS) ListFiles(name string, fileMode ...bool) ([]string, error) {
133133- fileMap := map[string]bool{}
134134+ fileSet := make(container.Set[string])
134135 for _, layer := range l.layers {
135136 infos, err := readDir(layer, name)
136137 if err != nil {
···138139 }
139140 for _, info := range infos {
140141 if shouldInclude(info, fileMode...) {
141141- fileMap[info.Name()] = true
142142+ fileSet.Add(info.Name())
142143 }
143144 }
144145 }
145145- files := make([]string, 0, len(fileMap))
146146- for file := range fileMap {
147147- files = append(files, file)
148148- }
146146+ files := fileSet.Values()
149147 sort.Strings(files)
150148 return files, nil
151149}
···161159}
162160163161func listAllFiles(layers []*Layer, name string, fileMode ...bool) ([]string, error) {
164164- fileMap := map[string]bool{}
162162+ fileSet := make(container.Set[string])
165163 var list func(dir string) error
166164 list = func(dir string) error {
167165 for _, layer := range layers {
···172170 for _, info := range infos {
173171 path := util.PathJoinRelX(dir, info.Name())
174172 if shouldInclude(info, fileMode...) {
175175- fileMap[path] = true
173173+ fileSet.Add(path)
176174 }
177175 if info.IsDir() {
178176 if err = list(path); err != nil {
···186184 if err := list(name); err != nil {
187185 return nil, err
188186 }
189189- var files []string
190190- for file := range fileMap {
191191- files = append(files, file)
192192- }
187187+ files := fileSet.Values()
193188 sort.Strings(files)
194189 return files, nil
195190}
+5-5
modules/templates/util_dict.go
···99 "html/template"
1010 "reflect"
11111212+ "code.gitea.io/gitea/modules/container"
1213 "code.gitea.io/gitea/modules/json"
1314 "code.gitea.io/gitea/modules/setting"
1415)
···5152 return m, nil
5253}
53545454-func dumpVarMarshalable(v any, dumped map[uintptr]bool) (ret any, ok bool) {
5555+func dumpVarMarshalable(v any, dumped container.Set[uintptr]) (ret any, ok bool) {
5556 if v == nil {
5657 return nil, true
5758 }
···6162 }
6263 if e.CanAddr() {
6364 addr := e.UnsafeAddr()
6464- if dumped[addr] {
6565+ if !dumped.Add(addr) {
6566 return "[dumped]", false
6667 }
6767- dumped[addr] = true
6868- defer delete(dumped, addr)
6868+ defer dumped.Remove(addr)
6969 }
7070 switch e.Kind() {
7171 case reflect.Bool, reflect.String,
···107107 if setting.IsProd {
108108 return "<pre>dumpVar: only available in dev mode</pre>"
109109 }
110110- m, ok := dumpVarMarshalable(v, map[uintptr]bool{})
110110+ m, ok := dumpVarMarshalable(v, make(container.Set[uintptr]))
111111 var dumpStr string
112112 jsonBytes, err := json.MarshalIndent(m, "", " ")
113113 if err != nil {
+3-5
routers/api/actions/runner/utils.go
···1010 actions_model "code.gitea.io/gitea/models/actions"
1111 secret_model "code.gitea.io/gitea/models/secret"
1212 actions_module "code.gitea.io/gitea/modules/actions"
1313+ "code.gitea.io/gitea/modules/container"
1314 "code.gitea.io/gitea/modules/git"
1415 "code.gitea.io/gitea/modules/json"
1516 "code.gitea.io/gitea/modules/log"
···197198 if len(task.Job.Needs) == 0 {
198199 return nil, nil
199200 }
200200- needs := map[string]struct{}{}
201201- for _, v := range task.Job.Needs {
202202- needs[v] = struct{}{}
203203- }
201201+ needs := container.SetOf(task.Job.Needs...)
204202205203 jobs, _, err := actions_model.FindRunJobs(ctx, actions_model.FindRunJobOptions{RunID: task.Job.RunID})
206204 if err != nil {
···209207210208 ret := make(map[string]*runnerv1.TaskNeed, len(needs))
211209 for _, job := range jobs {
212212- if _, ok := needs[job.JobID]; !ok {
210210+ if !needs.Contains(job.JobID) {
213211 continue
214212 }
215213 if job.TaskID == 0 || !job.Status.IsDone() {
+2-5
routers/web/user/home.go
···567567568568 // Remove repositories that should not be shown,
569569 // which are repositories that have no issues and are not selected by the user.
570570- selectedReposMap := make(map[int64]struct{}, len(selectedRepoIDs))
571571- for _, repoID := range selectedRepoIDs {
572572- selectedReposMap[repoID] = struct{}{}
573573- }
570570+ selectedRepos := container.SetOf(selectedRepoIDs...)
574571 for k, v := range issueCountByRepo {
575575- if _, ok := selectedReposMap[k]; !ok && v == 0 {
572572+ if v == 0 && !selectedRepos.Contains(k) {
576573 delete(issueCountByRepo, k)
577574 }
578575 }
+4-3
services/auth/source/ldap/source_sync.go
···1313 "code.gitea.io/gitea/models/organization"
1414 user_model "code.gitea.io/gitea/models/user"
1515 auth_module "code.gitea.io/gitea/modules/auth"
1616+ "code.gitea.io/gitea/modules/container"
1617 "code.gitea.io/gitea/modules/log"
1718 "code.gitea.io/gitea/modules/util"
1819 source_service "code.gitea.io/gitea/services/auth/source"
···41424243 usernameUsers := make(map[string]*user_model.User, len(users))
4344 mailUsers := make(map[string]*user_model.User, len(users))
4444- keepActiveUsers := make(map[int64]struct{})
4545+ keepActiveUsers := make(container.Set[int64])
45464647 for _, u := range users {
4748 usernameUsers[u.LowerName] = u
···9798 }
989999100 if usr != nil {
100100- keepActiveUsers[usr.ID] = struct{}{}
101101+ keepActiveUsers.Add(usr.ID)
101102 } else if len(su.Username) == 0 {
102103 // we cannot create the user if su.Username is empty
103104 continue
···208209 // Deactivate users not present in LDAP
209210 if updateExisting {
210211 for _, usr := range users {
211211- if _, ok := keepActiveUsers[usr.ID]; ok {
212212+ if keepActiveUsers.Contains(usr.ID) {
212213 continue
213214 }
214215
+3-3
services/migrations/gitlab.go
···1414 "strings"
1515 "time"
16161717+ "code.gitea.io/gitea/modules/container"
1718 "code.gitea.io/gitea/modules/log"
1819 base "code.gitea.io/gitea/modules/migration"
1920 "code.gitea.io/gitea/modules/structs"
···673674674675func (g *GitlabDownloader) awardsToReactions(awards []*gitlab.AwardEmoji) []*base.Reaction {
675676 result := make([]*base.Reaction, 0, len(awards))
676676- uniqCheck := make(map[string]struct{})
677677+ uniqCheck := make(container.Set[string])
677678 for _, award := range awards {
678679 uid := fmt.Sprintf("%s%d", award.Name, award.User.ID)
679679- if _, ok := uniqCheck[uid]; !ok {
680680+ if uniqCheck.Add(uid) {
680681 result = append(result, &base.Reaction{
681682 UserID: int64(award.User.ID),
682683 UserName: award.User.Username,
683684 Content: award.Name,
684685 })
685685- uniqCheck[uid] = struct{}{}
686686 }
687687 }
688688 return result