]> source.dussan.org Git - jgit.git/commitdiff
SimilarityRenameDetector: Initialize sizes to 0 92/1892/2
authorShawn O. Pearce <spearce@spearce.org>
Thu, 11 Nov 2010 22:43:22 +0000 (14:43 -0800)
committerShawn O. Pearce <spearce@spearce.org>
Fri, 12 Nov 2010 19:57:02 +0000 (11:57 -0800)
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 <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityRenameDetector.java

index f47caf97f59ba413b03aa13063b00593a34cd489..3a9847545b5055f9462f023241637a5825ad2fe8 100644 (file)
@@ -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;
                                }