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/chunklist_test.go | |
parent | 822b86942c4ffb0dbf7fd096584d2970675f3ebc (diff) |
[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/chunklist_test.go')
-rw-r--r-- | src/chunklist_test.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/chunklist_test.go b/src/chunklist_test.go index 5f7481df..2523675a 100644 --- a/src/chunklist_test.go +++ b/src/chunklist_test.go @@ -3,6 +3,8 @@ package fzf import ( "fmt" "testing" + + "github.com/junegunn/fzf/src/util" ) func TestChunkList(t *testing.T) { @@ -10,7 +12,7 @@ func TestChunkList(t *testing.T) { sortCriteria = []criterion{byMatchLen, byLength} cl := NewChunkList(func(s []byte, i int) *Item { - return &Item{text: []rune(string(s)), rank: buildEmptyRank(int32(i * 2))} + return &Item{text: util.ToChars(s), rank: buildEmptyRank(int32(i * 2))} }) // Snapshot @@ -42,8 +44,8 @@ func TestChunkList(t *testing.T) { last := func(arr [5]int32) int32 { return arr[len(arr)-1] } - if string((*chunk1)[0].text) != "hello" || last((*chunk1)[0].rank) != 0 || - string((*chunk1)[1].text) != "world" || last((*chunk1)[1].rank) != 2 { + if (*chunk1)[0].text.ToString() != "hello" || last((*chunk1)[0].rank) != 0 || + (*chunk1)[1].text.ToString() != "world" || last((*chunk1)[1].rank) != 2 { t.Error("Invalid data") } if chunk1.IsFull() { |