diff options
author | Antonio Jesus Navarro Perez <antonio@sourced.tech> | 2017-02-23 17:32:44 +0100 |
---|---|---|
committer | Antonio Jesus Navarro Perez <antonio@sourced.tech> | 2017-02-27 09:45:00 +0100 |
commit | ae887c94d02661a91814fa05b4b54ba723220e6b (patch) | |
tree | 7cf8f3a1514b2a4aabec14d2134a381b07525fa1 /plumbing/cache/object.go | |
parent | 39f43b52a2bdfbc73703e2d09b575d49cd70ede8 (diff) | |
download | go-git-ae887c94d02661a91814fa05b4b54ba723220e6b.tar.gz |
plumbing/cache: specify units in memory size (Fix #234)
Diffstat (limited to 'plumbing/cache/object.go')
-rw-r--r-- | plumbing/cache/object.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/plumbing/cache/object.go b/plumbing/cache/object.go index 47e390b..f1af4e3 100644 --- a/plumbing/cache/object.go +++ b/plumbing/cache/object.go @@ -11,13 +11,13 @@ type ObjectFIFO struct { objects map[plumbing.Hash]plumbing.EncodedObject order *queue - maxSize int64 - actualSize int64 + maxSize FileSize + actualSize FileSize } // NewObjectFIFO returns an Object cache that keeps the newest objects that fit // into the specific memory size -func NewObjectFIFO(size int64) *ObjectFIFO { +func NewObjectFIFO(size FileSize) *ObjectFIFO { return &ObjectFIFO{ objects: make(map[plumbing.Hash]plumbing.EncodedObject), order: newQueue(initialQueueSize), @@ -30,7 +30,7 @@ func NewObjectFIFO(size int64) *ObjectFIFO { func (c *ObjectFIFO) Add(o plumbing.EncodedObject) { // if the size of the object is bigger or equal than the cache size, // skip it - if o.Size() >= c.maxSize { + if FileSize(o.Size()) >= c.maxSize { return } @@ -44,14 +44,14 @@ func (c *ObjectFIFO) Add(o plumbing.EncodedObject) { h := c.order.Pop() o := c.objects[h] if o != nil { - c.actualSize -= o.Size() + c.actualSize -= FileSize(o.Size()) delete(c.objects, h) } } c.objects[o.Hash()] = o c.order.Push(o.Hash()) - c.actualSize += o.Size() + c.actualSize += FileSize(o.Size()) } // Get returns an object by his hash. If the object is not found in the cache, it |