From e55e029ae8002c46e117d55bdfcc725b69bc21ef Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 10 Aug 2017 23:18:52 +0900 Subject: Build cache key for a pattern only once --- src/pattern.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/pattern.go') diff --git a/src/pattern.go b/src/pattern.go index 00e3a3a6..35a2f33c 100644 --- a/src/pattern.go +++ b/src/pattern.go @@ -47,6 +47,7 @@ type Pattern struct { text []rune termSets []termSet cacheable bool + cacheKey string delimiter Delimiter nth []Range procFun map[termType]algo.Algo @@ -134,6 +135,7 @@ func BuildPattern(fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case, delimiter: delimiter, procFun: make(map[termType]algo.Algo)} + ptr.cacheKey = ptr.buildCacheKey() ptr.procFun[termFuzzy] = fuzzyAlgo ptr.procFun[termEqual] = algo.EqualMatch ptr.procFun[termExact] = algo.ExactMatchNaive @@ -238,8 +240,7 @@ func (p *Pattern) AsString() string { return string(p.text) } -// CacheKey is used to build string to be used as the key of result cache -func (p *Pattern) CacheKey() string { +func (p *Pattern) buildCacheKey() string { if !p.extended { return p.AsString() } @@ -252,6 +253,11 @@ func (p *Pattern) CacheKey() string { return strings.Join(cacheableTerms, "\t") } +// CacheKey is used to build string to be used as the key of result cache +func (p *Pattern) CacheKey() string { + return p.cacheKey +} + // Match returns the list of matches Items in the given Chunk func (p *Pattern) Match(chunk *Chunk, slab *util.Slab) []Result { // ChunkCache: Exact match -- cgit v1.2.3