summaryrefslogtreecommitdiffstats
path: root/src/pattern.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-08-10 23:18:52 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-08-10 23:18:52 +0900
commite55e029ae8002c46e117d55bdfcc725b69bc21ef (patch)
tree4941bec840f27fa5c59f340878b6b934f27b3f86 /src/pattern.go
parent6b18b144cf0a608433009515cddef74737bfce56 (diff)
Build cache key for a pattern only once
Diffstat (limited to 'src/pattern.go')
-rw-r--r--src/pattern.go10
1 files changed, 8 insertions, 2 deletions
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