mirror of
https://github.com/junegunn/fzf.git
synced 2026-03-02 05:17:07 +08:00
Replace comparison-based pdqsort with LSD radix sort on the uint64 sort key. Radix sort is O(n) vs O(n log n) and avoids pointer-chasing cache misses in the comparison function. Sort scratch buffer is reused across iterations to reduce GC pressure. Benchmark (single-threaded, Chromium file list): - linux query (180K matches): ~16% faster - src query (high match count): ~31% faster - Rare matches: equivalent (falls back to pdqsort for n < 128)
21 lines
490 B
Go
21 lines
490 B
Go
//go:build !386 && !amd64 && !arm64
|
|
|
|
package fzf
|
|
|
|
func compareRanks(irank Result, jrank Result, tac bool) bool {
|
|
for idx := 3; idx >= 0; idx-- {
|
|
left := irank.points[idx]
|
|
right := jrank.points[idx]
|
|
if left < right {
|
|
return true
|
|
} else if left > right {
|
|
return false
|
|
}
|
|
}
|
|
return (irank.item.Index() <= jrank.item.Index()) != tac
|
|
}
|
|
|
|
func sortKey(r *Result) uint64 {
|
|
return uint64(r.points[0]) | uint64(r.points[1])<<16 | uint64(r.points[2])<<32 | uint64(r.points[3])<<48
|
|
}
|