From 0d171ba1d81886c6f9caf61867129e6daa268cd6 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 15 Aug 2017 01:10:41 +0900 Subject: Remove special nilItem --- src/core.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/core.go') diff --git a/src/core.go b/src/core.go index 0b90a51b..968d407b 100644 --- a/src/core.go +++ b/src/core.go @@ -85,29 +85,30 @@ func Run(opts *Options, revision string) { var chunkList *ChunkList header := make([]string, 0, opts.HeaderLines) if len(opts.WithNth) == 0 { - chunkList = NewChunkList(func(data []byte, index int) Item { + chunkList = NewChunkList(func(item *Item, data []byte, index int) bool { if len(header) < opts.HeaderLines { header = append(header, string(data)) eventBox.Set(EvtHeader, header) - return nilItem + return false } - chars, colors := ansiProcessor(data) - chars.Index = int32(index) - return Item{text: chars, colors: colors} + item.text, item.colors = ansiProcessor(data) + item.text.Index = int32(index) + return true }) } else { - chunkList = NewChunkList(func(data []byte, index int) Item { + chunkList = NewChunkList(func(item *Item, data []byte, index int) bool { tokens := Tokenize(string(data), opts.Delimiter) trans := Transform(tokens, opts.WithNth) transformed := joinTokens(trans) if len(header) < opts.HeaderLines { header = append(header, transformed) eventBox.Set(EvtHeader, header) - return nilItem + return false } - trimmed, colors := ansiProcessor([]byte(transformed)) - trimmed.Index = int32(index) - return Item{text: trimmed, colors: colors, origText: &data} + item.text, item.colors = ansiProcessor([]byte(transformed)) + item.text.Index = int32(index) + item.origText = &data + return true }) } @@ -151,8 +152,8 @@ func Run(opts *Options, revision string) { slab := util.MakeSlab(slab16Size, slab32Size) reader := Reader{ func(runes []byte) bool { - item := chunkList.trans(runes, 0) - if !item.Nil() { + item := Item{} + if chunkList.trans(&item, runes, 0) { if result, _, _ := pattern.MatchItem(&item, false, slab); result != nil { opts.Printer(item.text.ToString()) found = true -- cgit v1.2.3