From bbe10f4f7745000c121b629ff68e81bba5a497f6 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 18 Jul 2017 03:10:49 +0900 Subject: 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. --- src/cache.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/cache.go') 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 } -- cgit v1.2.3