diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2010-09-02 13:07:23 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-09-03 23:55:46 -0700 |
commit | 6938f99ef3338ec51b528800caf561dad30d9cec (patch) | |
tree | bd9292a72cb32474fec1f81e28a574809bbc8a1f | |
parent | fe8fe13349bb46ae690cfea6d3e57bfdac2301e4 (diff) | |
download | jgit-6938f99ef3338ec51b528800caf561dad30d9cec.tar.gz jgit-6938f99ef3338ec51b528800caf561dad30d9cec.zip |
Reduce compares in Edit.getType
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>
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/diff/Edit.java | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/Edit.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/Edit.java index 4a5de57b07..f0c7cdac5f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/Edit.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/Edit.java @@ -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). */ |