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/pattern.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/pattern.go') diff --git a/src/pattern.go b/src/pattern.go index 42a341b4..2df28795 100644 --- a/src/pattern.go +++ b/src/pattern.go @@ -49,7 +49,7 @@ type Pattern struct { cacheable bool delimiter Delimiter nth []Range - procFun map[termType]func(bool, bool, []rune, []rune) algo.Result + procFun map[termType]func(bool, bool, util.Chars, []rune) algo.Result } var ( @@ -125,7 +125,7 @@ func BuildPattern(fuzzy bool, extended bool, caseMode Case, forward bool, cacheable: cacheable, nth: nth, delimiter: delimiter, - procFun: make(map[termType]func(bool, bool, []rune, []rune) algo.Result)} + procFun: make(map[termType]func(bool, bool, util.Chars, []rune) algo.Result)} ptr.procFun[termFuzzy] = algo.FuzzyMatch ptr.procFun[termEqual] = algo.EqualMatch @@ -361,13 +361,13 @@ func (p *Pattern) prepareInput(item *Item) []Token { tokens := Tokenize(item.text, p.delimiter) ret = Transform(tokens, p.nth) } else { - ret = []Token{Token{text: item.text, prefixLength: 0, trimLength: util.TrimLen(item.text)}} + ret = []Token{Token{text: item.text, prefixLength: 0, trimLength: item.text.TrimLength()}} } item.transformed = ret return ret } -func (p *Pattern) iter(pfun func(bool, bool, []rune, []rune) algo.Result, +func (p *Pattern) iter(pfun func(bool, bool, util.Chars, []rune) algo.Result, tokens []Token, caseSensitive bool, forward bool, pattern []rune) (Offset, int32) { for _, part := range tokens { prefixLength := int32(part.prefixLength) -- cgit v1.2.3