summaryrefslogtreecommitdiffstats
path: root/src/pattern.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-07-16 23:31:19 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-07-16 23:34:32 +0900
commit9e85cba0d06025983a1a747bfc06c9955388d9c0 (patch)
tree8fe8dc1fd62ad3ecfbfd02e440fac6cfedcd313c /src/pattern.go
parent4b59ced08f1d417530a25af8fe13aa5d40579220 (diff)
Reduce memory footprint of Item struct
Diffstat (limited to 'src/pattern.go')
-rw-r--r--src/pattern.go19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/pattern.go b/src/pattern.go
index f1caeba2..07ed9cd8 100644
--- a/src/pattern.go
+++ b/src/pattern.go
@@ -247,7 +247,7 @@ func (p *Pattern) Match(chunk *Chunk, slab *util.Slab) []*Result {
// ChunkCache: Exact match
cacheKey := p.CacheKey()
if p.cacheable {
- if cached := _cache.Find(chunk, cacheKey); cached != nil {
+ if cached := _cache.Lookup(chunk, cacheKey); cached != nil {
return cached
}
}
@@ -352,18 +352,17 @@ func (p *Pattern) extendedMatch(item *Item, withPos bool, slab *util.Slab) ([]Of
}
func (p *Pattern) prepareInput(item *Item) []Token {
- if item.transformed != nil {
- return item.transformed
+ if len(p.nth) == 0 {
+ return []Token{Token{text: &item.text, prefixLength: 0}}
}
- var ret []Token
- if len(p.nth) == 0 {
- ret = []Token{Token{text: &item.text, prefixLength: 0}}
- } else {
- tokens := Tokenize(item.text, p.delimiter)
- ret = Transform(tokens, p.nth)
+ if item.transformed != nil {
+ return *item.transformed
}
- item.transformed = ret
+
+ tokens := Tokenize(item.text, p.delimiter)
+ ret := Transform(tokens, p.nth)
+ item.transformed = &ret
return ret
}