diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2016-08-19 02:39:32 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2016-08-19 02:39:32 +0900 |
commit | 37dc273148df0893053bf5cda0582a23f5c2b2d2 (patch) | |
tree | d90f5e96fa97de429265461268b1a6db2703cb4c /src/chunklist_test.go | |
parent | f7f01d109eb05c7eae82c243b6b6d5c5951ee707 (diff) |
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
Diffstat (limited to 'src/chunklist_test.go')
-rw-r--r-- | src/chunklist_test.go | 9 |
1 files changed, 3 insertions, 6 deletions
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() { |