diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2016-08-19 02:39:32 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2016-08-19 02:39:32 +0900 |
| commit | 37dc273148df0893053bf5cda0582a23f5c2b2d2 (patch) | |
| tree | d90f5e96fa97de429265461268b1a6db2703cb4c /src/cache.go | |
| parent | f7f01d109eb05c7eae82c243b6b6d5c5951ee707 (diff) | |
| download | fzf-37dc273148df0893053bf5cda0582a23f5c2b2d2.tar.gz | |
Micro-optimizations
- Make structs smaller
- Introduce Result struct and use it to represent matched items instead of
reusing Item struct for that purpose
- Avoid unnecessary memory allocation
- Avoid growing slice from the initial capacity
- Code cleanup
Diffstat (limited to 'src/cache.go')
| -rw-r--r-- | src/cache.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/cache.go b/src/cache.go index d2ec00b4..baf88dd8 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][]*Item +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 []*Item) { +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 []*Item) { } // Find is called to lookup ChunkCache -func (cc *ChunkCache) Find(chunk *Chunk, key string) ([]*Item, bool) { +func (cc *ChunkCache) Find(chunk *Chunk, key string) ([]*Result, bool) { if len(key) == 0 || !chunk.IsFull() { return nil, false } |
