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

[JGIT PATCH 2/2] Micro-optimize the merge base generator

From
Shawn O. Pearce <spearce@spearce.org>
Date
Mar 18, 2009, 18:01 UTC
Message-ID
<1237399309-29493-2-git-send-email-spearce@spearce.org>
In-Reply-To
<1237399309-29493-1-git-send-email-spearce@spearce.org>

Instead of doing 3 bit-wise and operations followed by 3 compares and two boolean and conditions on every commit we evaluate in the history, we can fold all of the tests into a pair of fields and do one bit mask and compare.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../spearce/jgit/revwalk/MergeBaseGenerator.java   |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/MergeBaseGenerator.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/MergeBaseGenerator.java
index 2eb9688..8694e4c 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/MergeBaseGenerator.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/MergeBaseGenerator.java
@@ -73,6 +73,10 @@
 
 	private int branchMask;
 
+	private int recarryTest;
+
+	private int recarryMask;
+
 	MergeBaseGenerator(final RevWalk w) {
 		walker = w;
 		pending = new DateRevQueue();
@@ -91,6 +95,12 @@ void init(final AbstractRevQueue p) {
 			// will be available for reuse when the walk resets.
 			//
 			walker.freeFlag(branchMask);
+
+			// Setup the condition used by carryOntoOne to detect a late
+			// merge base and produce it on the next round.
+			//
+			recarryTest = branchMask | POPPED;
+			recarryMask = branchMask | POPPED | MERGE_BASE;
 		}
 	}
 
@@ -187,8 +197,7 @@ private boolean carryOntoOne(final RevCommit p, final int carry) {
 		final boolean haveAll = (p.flags & carry) == carry;
 		p.flags |= carry;
 
-		if ((p.flags & POPPED) != 0 && (carry & MERGE_BASE) == 0
-				&& (p.flags & branchMask) == branchMask) {
+		if ((p.flags & recarryMask) == recarryTest) {
 			// We were popped without being a merge base, but we just got
 			// voted to be one. Inject ourselves back at the front of the
 			// pending queue and tell all of our ancestors they are within
-- 
1.6.2.1.337.g6270ba
Previous: Shawn O. Pearce
Message 2 of 2 in “Fix long running merge base computations”
  1. 1/2 Fix long running merge base computationsShawn O. Pearce, Mar 18, 2009
  2. 2/2 Micro-optimize the merge base generatorShawn O. Pearce, Mar 18, 2009

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.