loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

KN4CK3R and committed by
GitHub
53151530 815d267c

+36 -48
+4 -3
build/backport-locales.go
··· 12 12 "path/filepath" 13 13 "strings" 14 14 15 + "code.gitea.io/gitea/modules/container" 15 16 "code.gitea.io/gitea/modules/setting" 16 17 ) 17 18 ··· 58 59 59 60 // use old en-US as the base, and copy the new translations to the old locales 60 61 enUsOld := inisOld["options/locale/locale_en-US.ini"] 61 - brokenWarned := map[string]bool{} 62 + brokenWarned := make(container.Set[string]) 62 63 for path, iniOld := range inisOld { 63 64 if iniOld == enUsOld { 64 65 continue ··· 77 78 broken := oldStr != "" && strings.Count(oldStr, "%") != strings.Count(newStr, "%") 78 79 broken = broken || strings.Contains(oldStr, "\n") || strings.Contains(oldStr, "\n") 79 80 if broken { 80 - brokenWarned[secOld.Name()+"."+keyEnUs.Name()] = true 81 + brokenWarned.Add(secOld.Name() + "." + keyEnUs.Name()) 81 82 fmt.Println("----") 82 83 fmt.Printf("WARNING: skip broken locale: %s , [%s] %s\n", path, secEnUS.Name(), keyEnUs.Name()) 83 84 fmt.Printf("\told: %s\n", strings.ReplaceAll(oldStr, "\n", "\\n")) ··· 103 104 broken = broken || strings.HasPrefix(str, "`\"") 104 105 broken = broken || strings.Count(str, `"`)%2 == 1 105 106 broken = broken || strings.Count(str, "`")%2 == 1 106 - if broken && !brokenWarned[sec.Name()+"."+key.Name()] { 107 + if broken && !brokenWarned.Contains(sec.Name()+"."+key.Name()) { 107 108 fmt.Printf("WARNING: found broken locale: %s , [%s] %s\n", path, sec.Name(), key.Name()) 108 109 fmt.Printf("\tstr: %s\n", strings.ReplaceAll(str, "\n", "\\n")) 109 110 fmt.Println("----")
+5 -9
build/generate-go-licenses.go
··· 15 15 "regexp" 16 16 "sort" 17 17 "strings" 18 + 19 + "code.gitea.io/gitea/modules/container" 18 20 ) 19 21 20 22 // regexp is based on go-license, excluding README and NOTICE ··· 55 57 // yml 56 58 // 57 59 // It could be removed once we have a better regex. 58 - excludedExt := map[string]bool{ 59 - ".gitignore": true, 60 - ".go": true, 61 - ".mod": true, 62 - ".sum": true, 63 - ".toml": true, 64 - ".yml": true, 65 - } 60 + excludedExt := container.SetOf(".gitignore", ".go", ".mod", ".sum", ".toml", ".yml") 61 + 66 62 var paths []string 67 63 err := filepath.WalkDir(base, func(path string, entry fs.DirEntry, err error) error { 68 64 if err != nil { 69 65 return err 70 66 } 71 - if entry.IsDir() || !licenseRe.MatchString(entry.Name()) || excludedExt[filepath.Ext(entry.Name())] { 67 + if entry.IsDir() || !licenseRe.MatchString(entry.Name()) || excludedExt.Contains(filepath.Ext(entry.Name())) { 72 68 return nil 73 69 } 74 70 paths = append(paths, path)
+3 -3
models/unit/unit.go
··· 9 9 "strings" 10 10 11 11 "code.gitea.io/gitea/models/perm" 12 + "code.gitea.io/gitea/modules/container" 12 13 "code.gitea.io/gitea/modules/log" 13 14 "code.gitea.io/gitea/modules/setting" 14 15 ) ··· 318 319 319 320 // FindUnitTypes give the unit key names and return valid unique units and invalid keys 320 321 func FindUnitTypes(nameKeys ...string) (res []Type, invalidKeys []string) { 321 - m := map[Type]struct{}{} 322 + m := make(container.Set[Type]) 322 323 for _, key := range nameKeys { 323 324 t := TypeFromKey(key) 324 325 if t == TypeInvalid { 325 326 invalidKeys = append(invalidKeys, key) 326 - } else if _, ok := m[t]; !ok { 327 + } else if m.Add(t) { 327 328 res = append(res, t) 328 - m[t] = struct{}{} 329 329 } 330 330 } 331 331 return res, invalidKeys
+7 -12
modules/assetfs/layered.go
··· 14 14 "sort" 15 15 "time" 16 16 17 + "code.gitea.io/gitea/modules/container" 17 18 "code.gitea.io/gitea/modules/log" 18 19 "code.gitea.io/gitea/modules/process" 19 20 "code.gitea.io/gitea/modules/util" ··· 130 131 // * false: only directories will be returned. 131 132 // The returned files are sorted by name. 132 133 func (l *LayeredFS) ListFiles(name string, fileMode ...bool) ([]string, error) { 133 - fileMap := map[string]bool{} 134 + fileSet := make(container.Set[string]) 134 135 for _, layer := range l.layers { 135 136 infos, err := readDir(layer, name) 136 137 if err != nil { ··· 138 139 } 139 140 for _, info := range infos { 140 141 if shouldInclude(info, fileMode...) { 141 - fileMap[info.Name()] = true 142 + fileSet.Add(info.Name()) 142 143 } 143 144 } 144 145 } 145 - files := make([]string, 0, len(fileMap)) 146 - for file := range fileMap { 147 - files = append(files, file) 148 - } 146 + files := fileSet.Values() 149 147 sort.Strings(files) 150 148 return files, nil 151 149 } ··· 161 159 } 162 160 163 161 func listAllFiles(layers []*Layer, name string, fileMode ...bool) ([]string, error) { 164 - fileMap := map[string]bool{} 162 + fileSet := make(container.Set[string]) 165 163 var list func(dir string) error 166 164 list = func(dir string) error { 167 165 for _, layer := range layers { ··· 172 170 for _, info := range infos { 173 171 path := util.PathJoinRelX(dir, info.Name()) 174 172 if shouldInclude(info, fileMode...) { 175 - fileMap[path] = true 173 + fileSet.Add(path) 176 174 } 177 175 if info.IsDir() { 178 176 if err = list(path); err != nil { ··· 186 184 if err := list(name); err != nil { 187 185 return nil, err 188 186 } 189 - var files []string 190 - for file := range fileMap { 191 - files = append(files, file) 192 - } 187 + files := fileSet.Values() 193 188 sort.Strings(files) 194 189 return files, nil 195 190 }
+5 -5
modules/templates/util_dict.go
··· 9 9 "html/template" 10 10 "reflect" 11 11 12 + "code.gitea.io/gitea/modules/container" 12 13 "code.gitea.io/gitea/modules/json" 13 14 "code.gitea.io/gitea/modules/setting" 14 15 ) ··· 51 52 return m, nil 52 53 } 53 54 54 - func dumpVarMarshalable(v any, dumped map[uintptr]bool) (ret any, ok bool) { 55 + func dumpVarMarshalable(v any, dumped container.Set[uintptr]) (ret any, ok bool) { 55 56 if v == nil { 56 57 return nil, true 57 58 } ··· 61 62 } 62 63 if e.CanAddr() { 63 64 addr := e.UnsafeAddr() 64 - if dumped[addr] { 65 + if !dumped.Add(addr) { 65 66 return "[dumped]", false 66 67 } 67 - dumped[addr] = true 68 - defer delete(dumped, addr) 68 + defer dumped.Remove(addr) 69 69 } 70 70 switch e.Kind() { 71 71 case reflect.Bool, reflect.String, ··· 107 107 if setting.IsProd { 108 108 return "<pre>dumpVar: only available in dev mode</pre>" 109 109 } 110 - m, ok := dumpVarMarshalable(v, map[uintptr]bool{}) 110 + m, ok := dumpVarMarshalable(v, make(container.Set[uintptr])) 111 111 var dumpStr string 112 112 jsonBytes, err := json.MarshalIndent(m, "", " ") 113 113 if err != nil {
+3 -5
routers/api/actions/runner/utils.go
··· 10 10 actions_model "code.gitea.io/gitea/models/actions" 11 11 secret_model "code.gitea.io/gitea/models/secret" 12 12 actions_module "code.gitea.io/gitea/modules/actions" 13 + "code.gitea.io/gitea/modules/container" 13 14 "code.gitea.io/gitea/modules/git" 14 15 "code.gitea.io/gitea/modules/json" 15 16 "code.gitea.io/gitea/modules/log" ··· 197 198 if len(task.Job.Needs) == 0 { 198 199 return nil, nil 199 200 } 200 - needs := map[string]struct{}{} 201 - for _, v := range task.Job.Needs { 202 - needs[v] = struct{}{} 203 - } 201 + needs := container.SetOf(task.Job.Needs...) 204 202 205 203 jobs, _, err := actions_model.FindRunJobs(ctx, actions_model.FindRunJobOptions{RunID: task.Job.RunID}) 206 204 if err != nil { ··· 209 207 210 208 ret := make(map[string]*runnerv1.TaskNeed, len(needs)) 211 209 for _, job := range jobs { 212 - if _, ok := needs[job.JobID]; !ok { 210 + if !needs.Contains(job.JobID) { 213 211 continue 214 212 } 215 213 if job.TaskID == 0 || !job.Status.IsDone() {
+2 -5
routers/web/user/home.go
··· 567 567 568 568 // Remove repositories that should not be shown, 569 569 // which are repositories that have no issues and are not selected by the user. 570 - selectedReposMap := make(map[int64]struct{}, len(selectedRepoIDs)) 571 - for _, repoID := range selectedRepoIDs { 572 - selectedReposMap[repoID] = struct{}{} 573 - } 570 + selectedRepos := container.SetOf(selectedRepoIDs...) 574 571 for k, v := range issueCountByRepo { 575 - if _, ok := selectedReposMap[k]; !ok && v == 0 { 572 + if v == 0 && !selectedRepos.Contains(k) { 576 573 delete(issueCountByRepo, k) 577 574 } 578 575 }
+4 -3
services/auth/source/ldap/source_sync.go
··· 13 13 "code.gitea.io/gitea/models/organization" 14 14 user_model "code.gitea.io/gitea/models/user" 15 15 auth_module "code.gitea.io/gitea/modules/auth" 16 + "code.gitea.io/gitea/modules/container" 16 17 "code.gitea.io/gitea/modules/log" 17 18 "code.gitea.io/gitea/modules/util" 18 19 source_service "code.gitea.io/gitea/services/auth/source" ··· 41 42 42 43 usernameUsers := make(map[string]*user_model.User, len(users)) 43 44 mailUsers := make(map[string]*user_model.User, len(users)) 44 - keepActiveUsers := make(map[int64]struct{}) 45 + keepActiveUsers := make(container.Set[int64]) 45 46 46 47 for _, u := range users { 47 48 usernameUsers[u.LowerName] = u ··· 97 98 } 98 99 99 100 if usr != nil { 100 - keepActiveUsers[usr.ID] = struct{}{} 101 + keepActiveUsers.Add(usr.ID) 101 102 } else if len(su.Username) == 0 { 102 103 // we cannot create the user if su.Username is empty 103 104 continue ··· 208 209 // Deactivate users not present in LDAP 209 210 if updateExisting { 210 211 for _, usr := range users { 211 - if _, ok := keepActiveUsers[usr.ID]; ok { 212 + if keepActiveUsers.Contains(usr.ID) { 212 213 continue 213 214 } 214 215
+3 -3
services/migrations/gitlab.go
··· 14 14 "strings" 15 15 "time" 16 16 17 + "code.gitea.io/gitea/modules/container" 17 18 "code.gitea.io/gitea/modules/log" 18 19 base "code.gitea.io/gitea/modules/migration" 19 20 "code.gitea.io/gitea/modules/structs" ··· 673 674 674 675 func (g *GitlabDownloader) awardsToReactions(awards []*gitlab.AwardEmoji) []*base.Reaction { 675 676 result := make([]*base.Reaction, 0, len(awards)) 676 - uniqCheck := make(map[string]struct{}) 677 + uniqCheck := make(container.Set[string]) 677 678 for _, award := range awards { 678 679 uid := fmt.Sprintf("%s%d", award.Name, award.User.ID) 679 - if _, ok := uniqCheck[uid]; !ok { 680 + if uniqCheck.Add(uid) { 680 681 result = append(result, &base.Reaction{ 681 682 UserID: int64(award.User.ID), 682 683 UserName: award.User.Username, 683 684 Content: award.Name, 684 685 }) 685 - uniqCheck[uid] = struct{}{} 686 686 } 687 687 } 688 688 return result