refactor: use slices package for sorting (#10136)

Few more complicated usages of the sort packages are left.

### Purpose

Make progress towards replacing the sort package with slices package.
This commit is contained in:
Marcel Meyer
2025-05-26 20:37:49 +02:00
committed by GitHub
parent 905e5ec07f
commit 598915193a
18 changed files with 107 additions and 152 deletions

View File

@@ -20,7 +20,7 @@ import (
"os"
"path/filepath"
"runtime"
"sort"
"slices"
"strings"
"testing"
"time"
@@ -375,7 +375,9 @@ func mergeDirectoryContents(c ...[]fileInfo) []fileInfo {
i++
}
sort.Sort(fileInfoList(res))
slices.SortFunc(res, func(a, b fileInfo) int {
return strings.Compare(a.name, b.name)
})
return res
}
@@ -404,20 +406,6 @@ func (f fileInfo) String() string {
return fmt.Sprintf("%s %04o %d %x", f.name, f.mode, f.mod, f.hash)
}
type fileInfoList []fileInfo
func (l fileInfoList) Len() int {
return len(l)
}
func (l fileInfoList) Less(a, b int) bool {
return l[a].name < l[b].name
}
func (l fileInfoList) Swap(a, b int) {
l[a], l[b] = l[b], l[a]
}
func startWalker(dir string, res chan<- fileInfo, abort <-chan struct{}) chan error {
walker := func(path string, info os.FileInfo, err error) error {
if err != nil {