diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2016-08-14 00:39:44 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2016-08-14 00:41:30 +0900 |
| commit | 1d4057c20907b7d263d6f2b8cb4350a024859dfe (patch) | |
| tree | adb1edd9c4f1806cd65f8c5117645c22618c7301 /src/item_test.go | |
| parent | 822b86942c4ffb0dbf7fd096584d2970675f3ebc (diff) | |
| download | fzf-1d4057c20907b7d263d6f2b8cb4350a024859dfe.tar.gz | |
[perf] Avoid allocating rune array for ascii string
In the best case (all ascii), this reduces the memory footprint by 60%
and the response time by 15% to 20%. In the worst case (every line has
non-ascii characters), 3 to 4% overhead is observed.
Diffstat (limited to 'src/item_test.go')
| -rw-r--r-- | src/item_test.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/item_test.go b/src/item_test.go index d1c30d77..36a436d3 100644 --- a/src/item_test.go +++ b/src/item_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/junegunn/fzf/src/curses" + "github.com/junegunn/fzf/src/util" ) func TestOffsetSort(t *testing.T) { @@ -44,13 +45,13 @@ func TestItemRank(t *testing.T) { sortCriteria = []criterion{byMatchLen, byLength} strs := [][]rune{[]rune("foo"), []rune("foobar"), []rune("bar"), []rune("baz")} - item1 := Item{text: strs[0], offsets: []Offset{}, rank: [5]int32{0, 0, 0, 0, 1}} + item1 := Item{text: util.RunesToChars(strs[0]), offsets: []Offset{}, rank: [5]int32{0, 0, 0, 0, 1}} rank1 := item1.Rank(true) if rank1[0] != math.MaxInt32 || rank1[1] != 3 || rank1[4] != 1 { t.Error(item1.Rank(true)) } // Only differ in index - item2 := Item{text: strs[0], offsets: []Offset{}} + item2 := Item{text: util.RunesToChars(strs[0]), offsets: []Offset{}} items := []*Item{&item1, &item2} sort.Sort(ByRelevance(items)) @@ -66,10 +67,10 @@ func TestItemRank(t *testing.T) { } // Sort by relevance - item3 := Item{text: strs[1], rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}} - item4 := Item{text: strs[1], rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}} - item5 := Item{text: strs[2], rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}} - item6 := Item{text: strs[2], rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}} + item3 := Item{text: util.RunesToChars(strs[1]), rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}} + item4 := Item{text: util.RunesToChars(strs[1]), rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}} + item5 := Item{text: util.RunesToChars(strs[2]), rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}} + item6 := Item{text: util.RunesToChars(strs[2]), rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}} items = []*Item{&item1, &item2, &item3, &item4, &item5, &item6} sort.Sort(ByRelevance(items)) if items[0] != &item6 || items[1] != &item4 || |
