From 05653bda04a8199fceacd7f8b26c8af4dd8a8f3a Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 11 Nov 2010 14:43:22 -0800 Subject: [PATCH] SimilarityRenameDetector: Initialize sizes to 0 Setting the array elements to -1 is more expensive than relying on the allocator to zero the array for us first. Shifting the code to always add 1 to the size (so an empty file is actually 1 byte long) allows us to detect an unloaded size by comparing to 0, thus saving the array fill calls. Change-Id: Iad859e910655675b53ba70de8e6fceaef7cfcdd1 Signed-off-by: Shawn O. Pearce --- .../eclipse/jgit/diff/SimilarityRenameDetector.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityRenameDetector.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityRenameDetector.java index f47caf97f..3a9847545 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityRenameDetector.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityRenameDetector.java @@ -219,11 +219,6 @@ class SimilarityRenameDetector { long[] dstSizes = new long[dsts.size()]; BitSet dstTooLarge = null; - // Init the size arrays to some value that indicates that we haven't - // calculated the size yet. Since sizes cannot be negative, -1 will work - Arrays.fill(srcSizes, -1); - Arrays.fill(dstSizes, -1); - // Consider each pair of files, if the score is above the minimum // threshold we need record that scoring in the matrix so we can // later find the best matches. @@ -257,14 +252,14 @@ class SimilarityRenameDetector { } long srcSize = srcSizes[srcIdx]; - if (srcSize < 0) { - srcSize = size(OLD, srcEnt); + if (srcSize == 0) { + srcSize = size(OLD, srcEnt) + 1; srcSizes[srcIdx] = srcSize; } long dstSize = dstSizes[dstIdx]; - if (dstSize < 0) { - dstSize = size(NEW, dstEnt); + if (dstSize == 0) { + dstSize = size(NEW, dstEnt) + 1; dstSizes[dstIdx] = dstSize; }