summaryrefslogtreecommitdiff
path: root/src/cache.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-07-18 03:10:49 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-07-18 03:14:33 +0900
commitbbe10f4f7745000c121b629ff68e81bba5a497f6 (patch)
treef166d6e6d649763db438407ddc7a749d237df11e /src/cache.go
parent5e72709613b816531c1e0aed6a710257e08bb5d8 (diff)
downloadfzf-bbe10f4f7745000c121b629ff68e81bba5a497f6.tar.gz
Consolidate Result and rank structs
By not storing item index twice, we can cut down the size of Result struct and now it makes more sense to store and pass Results by values. Benchmarks show no degradation of performance by additional pointer indirection for looking up index.
Diffstat (limited to 'src/cache.go')
-rw-r--r--src/cache.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/cache.go b/src/cache.go
index 0540bdcf..df1a6ab7 100644
--- a/src/cache.go
+++ b/src/cache.go
@@ -3,7 +3,7 @@ package fzf
import "sync"
// queryCache associates strings to lists of items
-type queryCache map[string][]*Result
+type queryCache map[string][]Result
// ChunkCache associates Chunk and query string to lists of items
type ChunkCache struct {
@@ -17,7 +17,7 @@ func NewChunkCache() ChunkCache {
}
// Add adds the list to the cache
-func (cc *ChunkCache) Add(chunk *Chunk, key string, list []*Result) {
+func (cc *ChunkCache) Add(chunk *Chunk, key string, list []Result) {
if len(key) == 0 || !chunk.IsFull() || len(list) > queryCacheMax {
return
}
@@ -34,7 +34,7 @@ func (cc *ChunkCache) Add(chunk *Chunk, key string, list []*Result) {
}
// Lookup is called to lookup ChunkCache
-func (cc *ChunkCache) Lookup(chunk *Chunk, key string) []*Result {
+func (cc *ChunkCache) Lookup(chunk *Chunk, key string) []Result {
if len(key) == 0 || !chunk.IsFull() {
return nil
}
@@ -52,7 +52,7 @@ func (cc *ChunkCache) Lookup(chunk *Chunk, key string) []*Result {
return nil
}
-func (cc *ChunkCache) Search(chunk *Chunk, key string) []*Result {
+func (cc *ChunkCache) Search(chunk *Chunk, key string) []Result {
if len(key) == 0 || !chunk.IsFull() {
return nil
}