diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2017-07-15 19:35:27 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2017-07-16 23:34:32 +0900 |
commit | 8dbdd557302a282ff01dc1a89c4e5c28676bf72e (patch) | |
tree | 21f348eed7f850cdb7eeca587080de4bc6c97730 /src/pattern.go | |
parent | 6725151a994da0493aa2925c7fc141c1618bc3f9 (diff) |
Refactor cache lookup
- Remove multiple mutex locks in partial cache lookup
- Simplify return values
Diffstat (limited to 'src/pattern.go')
-rw-r--r-- | src/pattern.go | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/src/pattern.go b/src/pattern.go index 05b03b9e..f1caeba2 100644 --- a/src/pattern.go +++ b/src/pattern.go @@ -247,27 +247,13 @@ func (p *Pattern) Match(chunk *Chunk, slab *util.Slab) []*Result { // ChunkCache: Exact match cacheKey := p.CacheKey() if p.cacheable { - if cached, found := _cache.Find(chunk, cacheKey); found { + if cached := _cache.Find(chunk, cacheKey); cached != nil { return cached } } // Prefix/suffix cache - var space []*Result -Loop: - for idx := 1; idx < len(cacheKey); idx++ { - // [---------| ] | [ |---------] - // [--------| ] | [ |--------] - // [-------| ] | [ |-------] - prefix := cacheKey[:len(cacheKey)-idx] - suffix := cacheKey[idx:] - for _, substr := range [2]*string{&prefix, &suffix} { - if cached, found := _cache.Find(chunk, *substr); found { - space = cached - break Loop - } - } - } + space := _cache.Search(chunk, cacheKey) matches := p.matchChunk(chunk, space, slab) |