From f66d3c283c03fc34f0a16994385a1b5e98e11104 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 18 Aug 2008 16:53:15 -0700 Subject: [PATCH] Micro-optimize AbstractTreeIterator.pathCompare We were doing far too much work in pathCompare to handle cases that just cannot ever happen, such as if the paths were the same length but had different "last path char" and then somehow had different lengths. We also had the JVM doing a lot of comparsion ops just to return -1/0/1 when really we can get away with the non-zero result returned to the caller. Issuing just the subtraction and one comparsion to 0 is much quicker, JIT or not. Signed-off-by: Shawn O. Pearce Signed-off-by: Robin Rosenberg --- .../jgit/treewalk/AbstractTreeIterator.java | 44 +++------------------- 1 file changed, 5 insertions(+), 39 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java index bd75d2d4..31257b58 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java +++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java @@ -243,45 +243,11 @@ public abstract class AbstractTreeIterator { return cmp; } - if (cPos < aLen) { - final int aj = a[cPos] & 0xff; - final int lastb = lastPathChar(pMode); - if (aj < lastb) - return -1; - else if (aj > lastb) - return 1; - else if (cPos == aLen - 1) - return 0; - else - return -1; - } - - if (cPos < bLen) { - final int bk = b[cPos] & 0xff; - final int lasta = lastPathChar(mode); - if (lasta < bk) - return -1; - else if (lasta > bk) - return 1; - else if (cPos == bLen - 1) - return 0; - else - return 1; - } - - final int lasta = lastPathChar(mode); - final int lastb = lastPathChar(pMode); - if (lasta < lastb) - return -1; - else if (lasta > lastb) - return 1; - - if (aLen == bLen) - return 0; - else if (aLen < bLen) - return -1; - else - return 1; + if (cPos < aLen) + return (a[cPos] & 0xff) - lastPathChar(pMode); + if (cPos < bLen) + return lastPathChar(mode) - (b[cPos] & 0xff); + return lastPathChar(mode) - lastPathChar(pMode); } private static int lastPathChar(final int mode) { -- 2.11.4.GIT