summaryrefslogtreecommitdiffstats
path: root/routers/web
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2022-10-12 07:18:26 +0200
committerGitHub <noreply@github.com>2022-10-12 13:18:26 +0800
commit0e57ff7eee4ac71d923f970d15889ad4d50f97a9 (patch)
treee5a92c55af5366924bd40ae14b4bf12842239193 /routers/web
parente84558b0931309cf1f4f2767bc47296483b9b3e1 (diff)
downloadgitea-0e57ff7eee4ac71d923f970d15889ad4d50f97a9.tar.gz
gitea-0e57ff7eee4ac71d923f970d15889ad4d50f97a9.zip
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>
Diffstat (limited to 'routers/web')
-rw-r--r--routers/web/repo/issue.go14
-rw-r--r--routers/web/repo/lfs.go9
-rw-r--r--routers/web/repo/view.go9
3 files changed, 16 insertions, 16 deletions
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index 5dab770d55..38ad593c17 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -30,6 +30,7 @@ import (
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
+ "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
@@ -947,10 +948,11 @@ func ValidateRepoMetas(ctx *context.Context, form forms.CreateIssueForm, isPull
if err != nil {
return nil, nil, 0, 0
}
- labelIDMark := base.Int64sToMap(labelIDs)
+ labelIDMark := make(container.Set[int64])
+ labelIDMark.AddMultiple(labelIDs...)
for i := range labels {
- if labelIDMark[labels[i].ID] {
+ if labelIDMark.Contains(labels[i].ID) {
labels[i].IsChecked = true
hasSelected = true
}
@@ -1293,9 +1295,9 @@ func ViewIssue(ctx *context.Context) {
// Metas.
// Check labels.
- labelIDMark := make(map[int64]bool)
- for i := range issue.Labels {
- labelIDMark[issue.Labels[i].ID] = true
+ labelIDMark := make(container.Set[int64])
+ for _, label := range issue.Labels {
+ labelIDMark.Add(label.ID)
}
labels, err := issues_model.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
if err != nil {
@@ -1317,7 +1319,7 @@ func ViewIssue(ctx *context.Context) {
hasSelected := false
for i := range labels {
- if labelIDMark[labels[i].ID] {
+ if labelIDMark.Contains(labels[i].ID) {
labels[i].IsChecked = true
hasSelected = true
}
diff --git a/routers/web/repo/lfs.go b/routers/web/repo/lfs.go
index baec48bfea..633b8ab1a5 100644
--- a/routers/web/repo/lfs.go
+++ b/routers/web/repo/lfs.go
@@ -18,6 +18,7 @@ import (
git_model "code.gitea.io/gitea/models/git"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/charset"
+ "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/git/pipeline"
@@ -176,14 +177,12 @@ func LFSLocks(ctx *context.Context) {
return
}
- filemap := make(map[string]bool, len(filelist))
- for _, name := range filelist {
- filemap[name] = true
- }
+ fileset := make(container.Set[string], len(filelist))
+ fileset.AddMultiple(filelist...)
linkable := make([]bool, len(lfsLocks))
for i, lock := range lfsLocks {
- linkable[i] = filemap[lock.Path]
+ linkable[i] = fileset.Contains(lock.Path)
}
ctx.Data["Linkable"] = linkable
diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go
index 34305b7621..a43840467d 100644
--- a/routers/web/repo/view.go
+++ b/routers/web/repo/view.go
@@ -28,6 +28,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/charset"
+ "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/highlight"
@@ -811,16 +812,14 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri
defer cancel()
}
- selected := map[string]bool{}
- for _, pth := range ctx.FormStrings("f[]") {
- selected[pth] = true
- }
+ selected := make(container.Set[string])
+ selected.AddMultiple(ctx.FormStrings("f[]")...)
entries := allEntries
if len(selected) > 0 {
entries = make(git.Entries, 0, len(selected))
for _, entry := range allEntries {
- if selected[entry.Name()] {
+ if selected.Contains(entry.Name()) {
entries = append(entries, entry)
}
}