mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
More micro-optimizations
This commit is contained in:
parent
939f3eee97
commit
0f7d6b5bc4
3 changed files with 19 additions and 25 deletions
|
@ -27,11 +27,8 @@ func ParseIndexGroups(spec string) IndexGroups {
|
||||||
for _, g := range split {
|
for _, g := range split {
|
||||||
sub := indexGroupsRx.FindStringSubmatch(g)
|
sub := indexGroupsRx.FindStringSubmatch(g)
|
||||||
if len(sub) > 0 {
|
if len(sub) > 0 {
|
||||||
i := 0
|
for _, c := range sub[2] {
|
||||||
chars := strings.Split(sub[2], "")
|
parsed[string(c)] = sub[1]
|
||||||
for _, c := range chars {
|
|
||||||
parsed[c] = sub[1]
|
|
||||||
i++
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
parsed[g] = g
|
parsed[g] = g
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package merge
|
package merge
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cmp"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"sort"
|
"slices"
|
||||||
|
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FS implements a simple merged fs.FS, that can combine a Base FS with an Overlay FS. The semantics are:
|
// FS implements a simple merged fs.FS, that can combine a Base FS with an Overlay FS. The semantics are:
|
||||||
|
@ -44,33 +47,26 @@ func (m FS) Open(name string) (fs.File, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m FS) mergeDirs(name string, info fs.FileInfo, baseDir fs.ReadDirFile, overlayDir fs.ReadDirFile) (fs.File, error) {
|
func (m FS) mergeDirs(name string, info fs.FileInfo, baseDir fs.ReadDirFile, overlayDir fs.ReadDirFile) (fs.File, error) {
|
||||||
merged := map[string]fs.DirEntry{}
|
|
||||||
|
|
||||||
baseFiles, err := baseDir.ReadDir(-1)
|
baseFiles, err := baseDir.ReadDir(-1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sort.Slice(baseFiles, func(i, j int) bool { return baseFiles[i].Name() < baseFiles[j].Name() })
|
|
||||||
|
|
||||||
overlayFiles, err := overlayDir.ReadDir(-1)
|
overlayFiles, err := overlayDir.ReadDir(-1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
overlayFiles = nil
|
overlayFiles = nil
|
||||||
}
|
}
|
||||||
sort.Slice(overlayFiles, func(i, j int) bool { return overlayFiles[i].Name() < overlayFiles[j].Name() })
|
|
||||||
|
|
||||||
|
merged := map[string]fs.DirEntry{}
|
||||||
for _, f := range baseFiles {
|
for _, f := range baseFiles {
|
||||||
merged[f.Name()] = f
|
merged[f.Name()] = f
|
||||||
}
|
}
|
||||||
for _, f := range overlayFiles {
|
for _, f := range overlayFiles {
|
||||||
merged[f.Name()] = f
|
merged[f.Name()] = f
|
||||||
}
|
}
|
||||||
|
entries := maps.Values(merged)
|
||||||
|
|
||||||
var entries []fs.DirEntry
|
slices.SortFunc(entries, func(i, j fs.DirEntry) int { return cmp.Compare(i.Name(), j.Name()) })
|
||||||
for _, i := range merged {
|
|
||||||
entries = append(entries, i)
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Slice(entries, func(i, j int) bool { return entries[i].Name() < entries[j].Name() })
|
|
||||||
return &mergedDir{
|
return &mergedDir{
|
||||||
name: name,
|
name: name,
|
||||||
info: info,
|
info: info,
|
||||||
|
|
|
@ -4,16 +4,17 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var utf8ToAscii = strings.NewReplacer(
|
||||||
|
"–", "-",
|
||||||
|
"‐", "-",
|
||||||
|
"“", `"`,
|
||||||
|
"”", `"`,
|
||||||
|
"‘", `'`,
|
||||||
|
"’", `'`,
|
||||||
|
)
|
||||||
|
|
||||||
func Clear(name string) string {
|
func Clear(name string) string {
|
||||||
r := strings.NewReplacer(
|
return utf8ToAscii.Replace(name)
|
||||||
"–", "-",
|
|
||||||
"‐", "-",
|
|
||||||
"“", `"`,
|
|
||||||
"”", `"`,
|
|
||||||
"‘", `'`,
|
|
||||||
"’", `'`,
|
|
||||||
)
|
|
||||||
return r.Replace(name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func LongestCommonPrefix(list []string) string {
|
func LongestCommonPrefix(list []string) string {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue