git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 3/4] Micro-optimize TreeWalk's exitSubtree implementation

From
Shawn O. Pearce <spearce@spearce.org>
Date
Aug 21, 2008, 20:57 UTC
Message-ID
<1219352258-15431-3-git-send-email-spearce@spearce.org>
In-Reply-To
<1219352258-15431-2-git-send-email-spearce@spearce.org>

Rather than recomputing the min over again we can take the hint that the prior min (the one that describes the tree we just left) must be one that matches itself. There may be more than one such case, as a min could be found and match itself and later another min is found. So we fall back into a pathCompare if we identify more than one.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../src/org/spearce/jgit/treewalk/TreeWalk.java    |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java
index 6d0ef02..ef27e4e 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java
@@ -722,11 +722,19 @@ void skipEntriesEqual() throws CorruptObjectException {
 		}
 	}
 
-	private void exitSubtree() throws CorruptObjectException {
+	private void exitSubtree() {
 		depth--;
 		for (int i = 0; i < trees.length; i++)
 			trees[i] = trees[i].parent;
-		currentHead = min();
+
+		AbstractTreeIterator minRef = null;
+		for (final AbstractTreeIterator t : trees) {
+			if (t.matches != t)
+				continue;
+			if (minRef == null || t.pathCompare(minRef) < 0)
+				minRef = t;
+		}
+		currentHead = minRef;
 	}
 
 	private CanonicalTreeParser parserFor(final ObjectId id)
-- 
1.6.0.112.g9c75
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 3 of 6 in “Simplify and micro-optimize WorkingTreeIterator.ENTRY_CMP”
  1. 1/4 Simplify and micro-optimize WorkingTreeIterator.ENTRY_CMPShawn O. Pearce, Aug 21, 2008
  2. 2/4 Support post order tree handling during TreeWalkShawn O. Pearce, Aug 21, 2008
  3. 3/4 Micro-optimize TreeWalk's exitSubtree implementationShawn O. Pearce, Aug 21, 2008
  4. 4/4 Add getNameString to TreeWalk to get only the last path componentShawn O. Pearce, Aug 21, 2008
  5. Robin RosenbergAug 22, 2008
  6. Shawn O. PearceAug 22, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.