diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2017-07-31 03:21:35 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2017-08-01 03:44:38 +0900 |
commit | f4b46fad27b4d4f7f3f5649b5f2948c298c3a5ae (patch) | |
tree | df2899d982141bc3cc2e5372b583d29f7e584457 /src/pattern.go | |
parent | 9d2c6a95f4259e9bccc114f48b3b3d21a357b6d1 (diff) |
Inline function calls in a tight loop
Manually inline function calls in a tight loop as Go compiler does not
inline non-leaf functions. It is observed that this unpleasant code
change resulted up to 10% performance improvement.
Diffstat (limited to 'src/pattern.go')
-rw-r--r-- | src/pattern.go | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/pattern.go b/src/pattern.go index 64296d71..8cb20983 100644 --- a/src/pattern.go +++ b/src/pattern.go @@ -301,7 +301,12 @@ func (p *Pattern) MatchItem(item *Item, withPos bool, slab *util.Slab) (*Result, } func (p *Pattern) basicMatch(item *Item, withPos bool, slab *util.Slab) (Offset, int, *[]int) { - input := p.prepareInput(item) + var input []Token + if len(p.nth) == 0 { + input = []Token{Token{text: &item.text, prefixLength: 0}} + } else { + input = p.transformInput(item) + } if p.fuzzy { return p.iter(p.fuzzyAlgo, input, p.caseSensitive, p.normalize, p.forward, p.text, withPos, slab) } @@ -309,7 +314,12 @@ func (p *Pattern) basicMatch(item *Item, withPos bool, slab *util.Slab) (Offset, } func (p *Pattern) extendedMatch(item *Item, withPos bool, slab *util.Slab) ([]Offset, int, *[]int) { - input := p.prepareInput(item) + var input []Token + if len(p.nth) == 0 { + input = []Token{Token{text: &item.text, prefixLength: 0}} + } else { + input = p.transformInput(item) + } offsets := []Offset{} var totalScore int var allPos *[]int @@ -353,11 +363,7 @@ func (p *Pattern) extendedMatch(item *Item, withPos bool, slab *util.Slab) ([]Of return offsets, totalScore, allPos } -func (p *Pattern) prepareInput(item *Item) []Token { - if len(p.nth) == 0 { - return []Token{Token{text: &item.text, prefixLength: 0}} - } - +func (p *Pattern) transformInput(item *Item) []Token { if item.transformed != nil { return *item.transformed } |