From 809027f163d2b7732b50d9cf7bbc501cc8ed3a1b Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Tue, 23 Apr 2019 22:16:02 +0200 Subject: Add one more cache check to the iterator Signed-off-by: Filip Navara --- plumbing/format/packfile/packfile.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'plumbing/format/packfile') diff --git a/plumbing/format/packfile/packfile.go b/plumbing/format/packfile/packfile.go index 895c152..a9121c4 100644 --- a/plumbing/format/packfile/packfile.go +++ b/plumbing/format/packfile/packfile.go @@ -490,13 +490,23 @@ func (i *objectIter) Next() (plumbing.EncodedObject, error) { continue } } else { + if obj, ok := i.p.cacheGet(e.Hash); ok { + if obj.Type() != i.typ { + continue + } + return obj, nil + } + h, err := i.p.objectHeaderAtOffset(int64(e.Offset)) if err != nil { return nil, err } typ, err := i.p.getObjectType(h) - if err == nil && typ != i.typ { + if err != nil { + return nil, err + } + if typ != i.typ { continue } @@ -504,7 +514,7 @@ func (i *objectIter) Next() (plumbing.EncodedObject, error) { } } - obj, err := i.p.GetByOffset(int64(e.Offset)) + obj, err := i.p.objectAtOffset(int64(e.Offset), e.Hash) if err != nil { return nil, err } -- cgit