aboutsummaryrefslogtreecommitdiffstats
path: root/modules/assetfs
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2023-08-30 08:55:25 +0200
committerGitHub <noreply@github.com>2023-08-30 06:55:25 +0000
commit5315153059529f03b06c8f25487ffcc21ae3163f (patch)
treeb5f90daf2f1916f37656369865706d95872a7ae7 /modules/assetfs
parent815d267c8031daa19b82b291a6393a54715567c0 (diff)
downloadgitea-5315153059529f03b06c8f25487ffcc21ae3163f.tar.gz
gitea-5315153059529f03b06c8f25487ffcc21ae3163f.zip
Use `Set[Type]` instead of `map[Type]bool/struct{}`. (#26804)
Diffstat (limited to 'modules/assetfs')
-rw-r--r--modules/assetfs/layered.go19
1 files changed, 7 insertions, 12 deletions
diff --git a/modules/assetfs/layered.go b/modules/assetfs/layered.go
index d69732f81b..9678d23ad6 100644
--- a/modules/assetfs/layered.go
+++ b/modules/assetfs/layered.go
@@ -14,6 +14,7 @@ import (
"sort"
"time"
+ "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/util"
@@ -130,7 +131,7 @@ func readDir(layer *Layer, name string) ([]fs.FileInfo, error) {
// * false: only directories will be returned.
// The returned files are sorted by name.
func (l *LayeredFS) ListFiles(name string, fileMode ...bool) ([]string, error) {
- fileMap := map[string]bool{}
+ fileSet := make(container.Set[string])
for _, layer := range l.layers {
infos, err := readDir(layer, name)
if err != nil {
@@ -138,14 +139,11 @@ func (l *LayeredFS) ListFiles(name string, fileMode ...bool) ([]string, error) {
}
for _, info := range infos {
if shouldInclude(info, fileMode...) {
- fileMap[info.Name()] = true
+ fileSet.Add(info.Name())
}
}
}
- files := make([]string, 0, len(fileMap))
- for file := range fileMap {
- files = append(files, file)
- }
+ files := fileSet.Values()
sort.Strings(files)
return files, nil
}
@@ -161,7 +159,7 @@ func (l *LayeredFS) ListAllFiles(name string, fileMode ...bool) ([]string, error
}
func listAllFiles(layers []*Layer, name string, fileMode ...bool) ([]string, error) {
- fileMap := map[string]bool{}
+ fileSet := make(container.Set[string])
var list func(dir string) error
list = func(dir string) error {
for _, layer := range layers {
@@ -172,7 +170,7 @@ func listAllFiles(layers []*Layer, name string, fileMode ...bool) ([]string, err
for _, info := range infos {
path := util.PathJoinRelX(dir, info.Name())
if shouldInclude(info, fileMode...) {
- fileMap[path] = true
+ fileSet.Add(path)
}
if info.IsDir() {
if err = list(path); err != nil {
@@ -186,10 +184,7 @@ func listAllFiles(layers []*Layer, name string, fileMode ...bool) ([]string, err
if err := list(name); err != nil {
return nil, err
}
- var files []string
- for file := range fileMap {
- files = append(files, file)
- }
+ files := fileSet.Values()
sort.Strings(files)
return files, nil
}