From 1d4057c20907b7d263d6f2b8cb4350a024859dfe Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 14 Aug 2016 00:39:44 +0900 Subject: [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. --- src/chunklist_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/chunklist_test.go') 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() { -- cgit v1.2.3