From 3fa7d3a2d22c3f6e1b800955e7e2bc5ad3df80c4 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 1 Sep 2010 16:54:20 -0700 Subject: [PATCH] Use int[] rather than IntList for RawText hashes We know exactly how many lines we need by the time we compute our per-line hashes, as we have already built the lines IntList to give us the starting position of each line in the buffer. Using that we can properly size the array, and don't need the dynamic growing feature of IntList. So drop the indirection and just use a fixed size array. Change-Id: I5c8c592514692a8abff51e5928aedcf71e100365 Signed-off-by: Shawn O. Pearce --- .../src/org/eclipse/jgit/diff/RawText.java | 12 +++++------- .../jgit/diff/RawTextIgnoreAllWhitespace.java | 2 +- .../jgit/diff/RawTextIgnoreLeadingWhitespace.java | 2 +- .../jgit/diff/RawTextIgnoreTrailingWhitespace.java | 2 +- .../jgit/diff/RawTextIgnoreWhitespaceChange.java | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java index 4befe586c..ad81de58c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java @@ -95,7 +95,7 @@ public class RawText implements Sequence { protected final IntList lines; /** Hash code for each line, for fast equality elimination. */ - protected final IntList hashes; + protected final int[] hashes; /** * Create a new sequence from an existing content byte array. @@ -140,7 +140,7 @@ public class RawText implements Sequence { private static boolean equals(final RawText a, final int ai, final RawText b, final int bi) { - if (a.hashes.get(ai) != b.hashes.get(bi)) + if (a.hashes[ai] != b.hashes[bi]) return false; int as = a.lines.get(ai); @@ -197,15 +197,13 @@ public class RawText implements Sequence { return content[end - 1] != '\n'; } - private IntList computeHashes() { - final IntList r = new IntList(lines.size()); - r.add(0); + private int[] computeHashes() { + final int[] r = new int[lines.size()]; for (int lno = 1; lno < lines.size() - 1; lno++) { final int ptr = lines.get(lno); final int end = lines.get(lno + 1); - r.add(hashLine(content, ptr, end)); + r[lno] = hashLine(content, ptr, end); } - r.add(0); return r; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreAllWhitespace.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreAllWhitespace.java index 211618a3f..855a87242 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreAllWhitespace.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreAllWhitespace.java @@ -79,7 +79,7 @@ public class RawTextIgnoreAllWhitespace extends RawText { private static boolean equals(final RawText a, final int ai, final RawText b, final int bi) { - if (a.hashes.get(ai) != b.hashes.get(bi)) + if (a.hashes[ai] != b.hashes[bi]) return false; int as = a.lines.get(ai); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreLeadingWhitespace.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreLeadingWhitespace.java index 23778973b..df4805a4c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreLeadingWhitespace.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreLeadingWhitespace.java @@ -78,7 +78,7 @@ public class RawTextIgnoreLeadingWhitespace extends RawText { private static boolean equals(final RawText a, final int ai, final RawText b, final int bi) { - if (a.hashes.get(ai) != b.hashes.get(bi)) + if (a.hashes[ai] != b.hashes[bi]) return false; int as = a.lines.get(ai); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreTrailingWhitespace.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreTrailingWhitespace.java index 3feb2e783..5e69eaabd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreTrailingWhitespace.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreTrailingWhitespace.java @@ -78,7 +78,7 @@ public class RawTextIgnoreTrailingWhitespace extends RawText { private static boolean equals(final RawText a, final int ai, final RawText b, final int bi) { - if (a.hashes.get(ai) != b.hashes.get(bi)) + if (a.hashes[ai] != b.hashes[bi]) return false; int as = a.lines.get(ai); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreWhitespaceChange.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreWhitespaceChange.java index e6bd8e98b..2d1b9772f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreWhitespaceChange.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextIgnoreWhitespaceChange.java @@ -81,7 +81,7 @@ public class RawTextIgnoreWhitespaceChange extends RawText { private static boolean equals(final RawText a, final int ai, final RawText b, final int bi) { - if (a.hashes.get(ai) != b.hashes.get(bi)) + if (a.hashes[ai] != b.hashes[bi]) return false; int as = a.lines.get(ai);