mirror of
https://github.com/junegunn/fzf.git
synced 2026-04-27 09:41:31 +08:00
5887edc6ba
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
458 B
Go
21 lines
458 B
Go
//go:build 386 || amd64 || arm64
|
|
|
|
package fzf
|
|
|
|
import "unsafe"
|
|
|
|
func compareRanks(irank Result, jrank Result, tac bool) bool {
|
|
left := *(*uint64)(unsafe.Pointer(&irank.points[0]))
|
|
right := *(*uint64)(unsafe.Pointer(&jrank.points[0]))
|
|
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)(unsafe.Pointer(&r.points[0]))
|
|
}
|