Skip to content
Myr

Build cache key for a pattern only once

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 6b18b14 · Browse files · 1 file+8 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+8 added−2 removed

  • other:+8 added−2 removed

1 file+8 added−2 removed

modified:src/pattern.go+8 added-2 removed
45 unmodified lines
46 forward bool47 text []rune48 termSets []termSet49 cacheable bool50 cacheKey string51 delimiter Delimiter52 nth []Range53 procFun map[termType]algo.Algo54}
79 unmodified lines
134 nth: nth,135 delimiter: delimiter,136 procFun: make(map[termType]algo.Algo)}137138 ptr.cacheKey = ptr.buildCacheKey()139 ptr.procFun[termFuzzy] = fuzzyAlgo140 ptr.procFun[termEqual] = algo.EqualMatch141 ptr.procFun[termExact] = algo.ExactMatchNaive142 ptr.procFun[termPrefix] = algo.PrefixMatch
96 unmodified lines
239func (p *Pattern) AsString() string {240 return string(p.text)241}242241// CacheKey is used to build string to be used as the key of result cache242func (p *Pattern) CacheKey() string {243func (p *Pattern) buildCacheKey() string {244 if !p.extended {245 return p.AsString()246 }247 cacheableTerms := []string{}
4 unmodified lines
252 }253 return strings.Join(cacheableTerms, "\t")254}255256// CacheKey is used to build string to be used as the key of result cache257func (p *Pattern) CacheKey() string {258 return p.cacheKey259}260261// Match returns the list of matches Items in the given Chunk262func (p *Pattern) Match(chunk *Chunk, slab *util.Slab) []Result {263 // ChunkCache: Exact match264 cacheKey := p.CacheKey()
143 unmodified lines