From d4f3d5a16423fbf039644f04516c052d1654326c Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 15 Jul 2017 12:28:29 +0900 Subject: Remove pointer indirection by changing Chunk definition --- src/chunklist.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/chunklist.go') diff --git a/src/chunklist.go b/src/chunklist.go index a953fae9..1144274c 100644 --- a/src/chunklist.go +++ b/src/chunklist.go @@ -2,12 +2,12 @@ package fzf import "sync" -// Chunk is a list of Item pointers whose size has the upper limit of chunkSize -type Chunk []*Item // >>> []Item +// Chunk is a list of Items whose size has the upper limit of chunkSize +type Chunk []Item // ItemBuilder is a closure type that builds Item object from a pointer to a // string and an integer -type ItemBuilder func([]byte, int) *Item +type ItemBuilder func([]byte, int) Item // ChunkList is a list of Chunks type ChunkList struct { @@ -28,11 +28,11 @@ func NewChunkList(trans ItemBuilder) *ChunkList { func (c *Chunk) push(trans ItemBuilder, data []byte, index int) bool { item := trans(data, index) - if item != nil { - *c = append(*c, item) - return true + if item.Nil() { + return false } - return false + *c = append(*c, item) + return true } // IsFull returns true if the Chunk is full @@ -58,7 +58,7 @@ func (cl *ChunkList) Push(data []byte) bool { defer cl.mutex.Unlock() if len(cl.chunks) == 0 || cl.lastChunk().IsFull() { - newChunk := Chunk(make([]*Item, 0, chunkSize)) + newChunk := Chunk(make([]Item, 0, chunkSize)) cl.chunks = append(cl.chunks, &newChunk) } -- cgit v1.2.3