diff --git a/src/result.go b/src/result.go index 58cbafd..289d83a 100644 --- a/src/result.go +++ b/src/result.go @@ -70,7 +70,7 @@ func buildResult(item *Item, offsets []Offset, score int) Result { } } } - result.points[idx] = val + result.points[3-idx] = val } return result @@ -224,16 +224,3 @@ func (a ByRelevanceTac) Swap(i, j int) { func (a ByRelevanceTac) Less(i, j int) bool { return compareRanks(a[i], a[j], true) } - -func compareRanks(irank Result, jrank Result, tac bool) bool { - for idx := 0; idx < 4; 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 -} diff --git a/src/result_others.go b/src/result_others.go new file mode 100644 index 0000000..e3363a8 --- /dev/null +++ b/src/result_others.go @@ -0,0 +1,16 @@ +// +build !386,!amd64 + +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 +} diff --git a/src/result_test.go b/src/result_test.go index 1d86b1d..afd1730 100644 --- a/src/result_test.go +++ b/src/result_test.go @@ -59,10 +59,10 @@ func TestResultRank(t *testing.T) { strs := [][]rune{[]rune("foo"), []rune("foobar"), []rune("bar"), []rune("baz")} item1 := buildResult( withIndex(&Item{text: util.RunesToChars(strs[0])}, 1), []Offset{}, 2) - if item1.points[0] != math.MaxUint16-2 || // Bonus - item1.points[1] != 3 || // Length - item1.points[2] != 0 || // Unused - item1.points[3] != 0 || // Unused + if item1.points[3] != math.MaxUint16-2 || // Bonus + item1.points[2] != 3 || // Length + item1.points[1] != 0 || // Unused + item1.points[0] != 0 || // Unused item1.item.Index() != 1 { t.Error(item1) } diff --git a/src/result_x86.go b/src/result_x86.go new file mode 100644 index 0000000..60e26e9 --- /dev/null +++ b/src/result_x86.go @@ -0,0 +1,16 @@ +// +build 386 amd64 + +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 +}