Improve prefix/suffix cache lookup
This commit is contained in:
parent
bd7331ecf5
commit
313578a1a0
@ -194,24 +194,19 @@ func (p *Pattern) Match(chunk *Chunk) []*Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChunkCache: Prefix match
|
// ChunkCache: Prefix/suffix match
|
||||||
foundPrefixCache := false
|
Loop:
|
||||||
for idx := len(cacheKey) - 1; idx > 0; idx-- {
|
for idx := 1; idx < len(cacheKey); idx++ {
|
||||||
if cached, found := _cache.Find(chunk, cacheKey[:idx]); found {
|
// [---------| ] | [ |---------]
|
||||||
cachedChunk := Chunk(cached)
|
// [--------| ] | [ |--------]
|
||||||
space = &cachedChunk
|
// [-------| ] | [ |-------]
|
||||||
foundPrefixCache = true
|
prefix := cacheKey[:len(cacheKey)-idx]
|
||||||
break
|
suffix := cacheKey[idx:]
|
||||||
}
|
for _, substr := range [2]*string{&prefix, &suffix} {
|
||||||
}
|
if cached, found := _cache.Find(chunk, *substr); found {
|
||||||
|
|
||||||
// ChunkCache: Suffix match
|
|
||||||
if !foundPrefixCache {
|
|
||||||
for idx := 1; idx < len(cacheKey); idx++ {
|
|
||||||
if cached, found := _cache.Find(chunk, cacheKey[idx:]); found {
|
|
||||||
cachedChunk := Chunk(cached)
|
cachedChunk := Chunk(cached)
|
||||||
space = &cachedChunk
|
space = &cachedChunk
|
||||||
break
|
break Loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user