mirror of
https://github.com/junegunn/fzf
synced 2026-07-28 17:51:42 +00:00
Skip all-zero passes in radix sort of results
Precompute OR of all sort keys; a byte position that is zero across every key contributes a no-op pass. Default two-criteria setup leaves the low 32 bits zero, so 4 of 8 passes are skipped without a histogram scan. 2x on the sort, 3-8% on high-match queries. No regression when all bytes are used.
This commit is contained in:
@@ -369,9 +369,21 @@ func radixSortResults(a []Result, tac bool, scratch []Result) []Result {
|
||||
src, dst := a, buf
|
||||
scattered := 0
|
||||
|
||||
// OR of all keys: a byte position that is zero here is zero in every key,
|
||||
// so its pass is a no-op and can be skipped without a histogram scan.
|
||||
// With the common two-criteria setup the low 32 bits are always zero.
|
||||
var keyOR uint64
|
||||
for i := range src {
|
||||
keyOR |= sortKey(&src[i])
|
||||
}
|
||||
|
||||
for pass := range 8 {
|
||||
shift := uint(pass) * 8
|
||||
|
||||
if byte(keyOR>>shift) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
var count [256]int
|
||||
for i := range src {
|
||||
count[byte(sortKey(&src[i])>>shift)]++
|
||||
|
||||
Reference in New Issue
Block a user