From c1002494eb389b703731c5267561a2703a8cd3b1 Mon Sep 17 00:00:00 2001 From: onee-only Date: Sun, 10 Mar 2024 15:50:17 +0900 Subject: plumbing: object, Optimize getNextFileCommit to reuse parent tree. --- plumbing/object/commit_walker_path.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'plumbing') diff --git a/plumbing/object/commit_walker_path.go b/plumbing/object/commit_walker_path.go index e054966..c1ec8ba 100644 --- a/plumbing/object/commit_walker_path.go +++ b/plumbing/object/commit_walker_path.go @@ -57,6 +57,8 @@ func (c *commitPathIter) Next() (*Commit, error) { } func (c *commitPathIter) getNextFileCommit() (*Commit, error) { + var parentTree, currentTree *Tree + for { // Parent-commit can be nil if the current-commit is the initial commit parentCommit, parentCommitErr := c.sourceIter.Next() @@ -68,13 +70,17 @@ func (c *commitPathIter) getNextFileCommit() (*Commit, error) { parentCommit = nil } - // Fetch the trees of the current and parent commits - currentTree, currTreeErr := c.currentCommit.Tree() - if currTreeErr != nil { - return nil, currTreeErr + if parentTree == nil { + var currTreeErr error + currentTree, currTreeErr = c.currentCommit.Tree() + if currTreeErr != nil { + return nil, currTreeErr + } + } else { + currentTree = parentTree + parentTree = nil } - var parentTree *Tree if parentCommit != nil { var parentTreeErr error parentTree, parentTreeErr = parentCommit.Tree() -- cgit From b274b225bf92f086d8e59d023ed436e97ed14062 Mon Sep 17 00:00:00 2001 From: onee-only Date: Sun, 10 Mar 2024 15:52:13 +0900 Subject: plumbing: object, Apply memoization in (*treeNoder).Children. --- plumbing/object/treenoder.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'plumbing') diff --git a/plumbing/object/treenoder.go b/plumbing/object/treenoder.go index 6e7b334..2adb645 100644 --- a/plumbing/object/treenoder.go +++ b/plumbing/object/treenoder.go @@ -88,7 +88,9 @@ func (t *treeNoder) Children() ([]noder.Noder, error) { } } - return transformChildren(parent) + var err error + t.children, err = transformChildren(parent) + return t.children, err } // Returns the children of a tree as treenoders. -- cgit