]> source.dussan.org Git - jgit.git/commitdiff
Reduce compares in Edit.getType 11/1511/2
authorShawn O. Pearce <spearce@spearce.org>
Thu, 2 Sep 2010 20:07:23 +0000 (13:07 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Sat, 4 Sep 2010 06:55:46 +0000 (23:55 -0700)
We can slightly optimize this method by removing some compares
based on knowledge of how the orderings have to work.  This way
a getType() invocation requires at most 2 int compares for any
result, vs. the 6 required to find REPLACE before.

Change-Id: I62a04cc513a6d28c300d1c1496a8608d5df4efa6
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/diff/Edit.java

index 4a5de57b07733d368f435cab9dfc1f03da070e2a..f0c7cdac5fafd03fbd74fc14ca5b7586ceae7271 100644 (file)
@@ -121,13 +121,18 @@ public class Edit {
 
        /** @return the type of this region */
        public final Type getType() {
-               if (beginA == endA && beginB < endB)
-                       return Type.INSERT;
-               if (beginA < endA && beginB == endB)
-                       return Type.DELETE;
-               if (beginA == endA && beginB == endB)
-                       return Type.EMPTY;
-               return Type.REPLACE;
+               if (beginA < endA) {
+                       if (beginB < endB)
+                               return Type.REPLACE;
+                       else /* if (beginB == endB) */
+                               return Type.DELETE;
+
+               } else /* if (beginA == endA) */{
+                       if (beginB < endB)
+                               return Type.INSERT;
+                       else /* if (beginB == endB) */
+                               return Type.EMPTY;
+               }
        }
 
        /** @return true if the edit is empty (lengths of both a and b is zero). */