From 8dbdd557302a282ff01dc1a89c4e5c28676bf72e Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 15 Jul 2017 19:35:27 +0900 Subject: Refactor cache lookup - Remove multiple mutex locks in partial cache lookup - Simplify return values --- src/pattern.go | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'src/pattern.go') 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) -- cgit v1.2.3