aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/packfile/decoder.go
diff options
context:
space:
mode:
authorJavi Fontan <jfontan@gmail.com>2017-12-20 15:11:38 +0100
committerJavi Fontan <jfontan@gmail.com>2017-12-20 15:27:45 +0100
commit962eeb399ce322daa4dd6522cdc91d277fbdba2c (patch)
tree3cfccb1568290dcb0db44cfa94f40b9b012d870f /plumbing/format/packfile/decoder.go
parent55b5d736682bf0e251c5bf83d1cf25c298d3ea0c (diff)
downloadgo-git-962eeb399ce322daa4dd6522cdc91d277fbdba2c.tar.gz
Enforce the use of cache in packfile decoder
Decoder object can make use of an object cache to speed up processing. Previously the only way to specify it was changing manually the struct generated by NewDecodeForFile. This lead to some instances to be created without it and penalized performance. Now the cache should be explicitly passed to the constructor function. NewDecoder now creates objects with a cache using the default size. A new helper function was added to create cache objects with the default size as this becomes a common task now: cache.NewObjectLRUDefault() Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'plumbing/format/packfile/decoder.go')
-rw-r--r--plumbing/format/packfile/decoder.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/plumbing/format/packfile/decoder.go b/plumbing/format/packfile/decoder.go
index ad72ea0..24493ec 100644
--- a/plumbing/format/packfile/decoder.go
+++ b/plumbing/format/packfile/decoder.go
@@ -80,15 +80,20 @@ type Decoder struct {
// If the ObjectStorer implements storer.Transactioner, a transaction is created
// during the Decode execution. If anything fails, Rollback is called
func NewDecoder(s *Scanner, o storer.EncodedObjectStorer) (*Decoder, error) {
- return NewDecoderForType(s, o, plumbing.AnyObject)
+ return NewDecoderForType(s, o, plumbing.AnyObject,
+ cache.NewObjectLRUDefault())
}
// NewDecoderForType returns a new Decoder but in this case for a specific object type.
// When an object is read using this Decoder instance and it is not of the same type of
// the specified one, nil will be returned. This is intended to avoid the content
-// deserialization of all the objects
+// deserialization of all the objects.
+//
+// cacheObject is an ObjectLRU that is used to speed up the process. If cache
+// is not needed you can pass nil. To create a cache object with the default
+// size you an use the helper cache.ObjectLRUDefault().
func NewDecoderForType(s *Scanner, o storer.EncodedObjectStorer,
- t plumbing.ObjectType) (*Decoder, error) {
+ t plumbing.ObjectType, cacheObject cache.Object) (*Decoder, error) {
if t == plumbing.OFSDeltaObject ||
t == plumbing.REFDeltaObject ||
@@ -101,8 +106,9 @@ func NewDecoderForType(s *Scanner, o storer.EncodedObjectStorer,
}
return &Decoder{
- s: s,
- o: o,
+ s: s,
+ o: o,
+ DeltaBaseCache: cacheObject,
idx: NewIndex(0),
offsetToType: make(map[int64]plumbing.ObjectType),