mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-26 18:22:09 +02:00
micro-optimization: compare using bytes.Compare instead of string based comparison
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package choose_files
|
package choose_files
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"cmp"
|
"cmp"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
@@ -133,7 +134,7 @@ func (fss *FileSystemScanner) Finished() bool {
|
|||||||
type sortable_dir_entry struct {
|
type sortable_dir_entry struct {
|
||||||
name string
|
name string
|
||||||
ftype fs.FileMode
|
ftype fs.FileMode
|
||||||
sort_key string
|
sort_key []byte
|
||||||
buf [unix.NAME_MAX + 1]byte
|
buf [unix.NAME_MAX + 1]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,10 +250,10 @@ func (fss *FileSystemScanner) worker() {
|
|||||||
arena[i].buf[0] = '1'
|
arena[i].buf[0] = '1'
|
||||||
}
|
}
|
||||||
n := as_lower(arena[i].name, arena[i].buf[1:])
|
n := as_lower(arena[i].name, arena[i].buf[1:])
|
||||||
arena[i].sort_key = utils.UnsafeBytesToString(arena[i].buf[:1+n])
|
arena[i].sort_key = arena[i].buf[:1+n]
|
||||||
sortable[i] = &arena[i]
|
sortable[i] = &arena[i]
|
||||||
}
|
}
|
||||||
slices.SortFunc(sortable, func(a, b *sortable_dir_entry) int { return cmp.Compare(a.sort_key, b.sort_key) })
|
slices.SortFunc(sortable, func(a, b *sortable_dir_entry) int { return bytes.Compare(a.sort_key, b.sort_key) })
|
||||||
ns := fss.results
|
ns := fss.results
|
||||||
new_sz := len(ns) + len(entries)
|
new_sz := len(ns) + len(entries)
|
||||||
if cap(ns) < new_sz {
|
if cap(ns) < new_sz {
|
||||||
|
|||||||
Reference in New Issue
Block a user