[JGIT PATCH 07/14] Micro-optimize AbstractTreeIterator.pathCompare

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <spearce@xxxxxxxxxxx>
---
 .../jgit/treewalk/AbstractTreeIterator.java        |   44 ++-----------------
 1 files 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 bd75d2d..31257b5 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 @@ int pathCompare(final AbstractTreeIterator p, final int pMode) {
 				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) {
-- 
1.6.0.87.g2858d

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux