From ae887c94d02661a91814fa05b4b54ba723220e6b Mon Sep 17 00:00:00 2001 From: Antonio Jesus Navarro Perez Date: Thu, 23 Feb 2017 17:32:44 +0100 Subject: plumbing/cache: specify units in memory size (Fix #234) --- plumbing/cache/object.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'plumbing/cache/object.go') 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 -- cgit