From 37dc273148df0893053bf5cda0582a23f5c2b2d2 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 19 Aug 2016 02:39:32 +0900 Subject: 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 --- src/chunklist_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/chunklist_test.go') diff --git a/src/chunklist_test.go b/src/chunklist_test.go index 2523675a..594daebb 100644 --- a/src/chunklist_test.go +++ b/src/chunklist_test.go @@ -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() { -- cgit v1.2.3