mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-13 19:25:47 -07:00
Micro-optimizations
- Make structs smaller - Introduce Result struct and use it to represent matched items instead of reusing Item struct for that purpose - Avoid unnecessary memory allocation - Avoid growing slice from the initial capacity - Code cleanup
This commit is contained in:
@@ -12,7 +12,7 @@ func TestChunkList(t *testing.T) {
|
||||
sortCriteria = []criterion{byMatchLen, byLength}
|
||||
|
||||
cl := NewChunkList(func(s []byte, i int) *Item {
|
||||
return &Item{text: util.ToChars(s), rank: buildEmptyRank(int32(i * 2))}
|
||||
return &Item{text: util.ToChars(s), index: int32(i * 2)}
|
||||
})
|
||||
|
||||
// Snapshot
|
||||
@@ -41,11 +41,8 @@ func TestChunkList(t *testing.T) {
|
||||
if len(*chunk1) != 2 {
|
||||
t.Error("Snapshot should contain only two items")
|
||||
}
|
||||
last := func(arr [5]int32) int32 {
|
||||
return arr[len(arr)-1]
|
||||
}
|
||||
if (*chunk1)[0].text.ToString() != "hello" || last((*chunk1)[0].rank) != 0 ||
|
||||
(*chunk1)[1].text.ToString() != "world" || last((*chunk1)[1].rank) != 2 {
|
||||
if (*chunk1)[0].text.ToString() != "hello" || (*chunk1)[0].index != 0 ||
|
||||
(*chunk1)[1].text.ToString() != "world" || (*chunk1)[1].index != 2 {
|
||||
t.Error("Invalid data")
|
||||
}
|
||||
if chunk1.IsFull() {
|
||||
|
Reference in New Issue
Block a user