]> source.dussan.org Git - jgit.git/commitdiff
SimilarityRenameDetector: Avoid allocating source index 91/1891/2
authorShawn O. Pearce <spearce@spearce.org>
Thu, 11 Nov 2010 22:29:11 +0000 (14:29 -0800)
committerShawn O. Pearce <spearce@spearce.org>
Fri, 12 Nov 2010 19:57:02 +0000 (11:57 -0800)
If the only file added is really small, and all of the deleted
files are really big, none of the permutations will match up due
to the sizes being too far apart to fit the current rename score.

Avoid allocating the really big deleted SimilarityIndex by deferring
its construction until at least one add along that row has a
reasonable chance of matching it.

This avoids expending a lot of CPU time looking at big deleted
binary files when a small modified text file was broken due to a
high percentage of changed lines.

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

index bf1bbda63bcd7e1c373c80449d17440b3f0ca3b8..f47caf97f59ba413b03aa13063b00593a34cd489 100644 (file)
@@ -229,20 +229,14 @@ class SimilarityRenameDetector {
                // later find the best matches.
                //
                int mNext = 0;
-               for (int srcIdx = 0; srcIdx < srcs.size(); srcIdx++) {
+               SRC: for (int srcIdx = 0; srcIdx < srcs.size(); srcIdx++) {
                        DiffEntry srcEnt = srcs.get(srcIdx);
                        if (!isFile(srcEnt.oldMode)) {
                                pm.update(dsts.size());
                                continue;
                        }
 
-                       SimilarityIndex s;
-                       try {
-                               s = hash(OLD, srcEnt);
-                       } catch (TableFullException tableFull) {
-                               tableOverflow = true;
-                               continue;
-                       }
+                       SimilarityIndex s = null;
 
                        for (int dstIdx = 0; dstIdx < dsts.size(); dstIdx++) {
                                DiffEntry dstEnt = dsts.get(dstIdx);
@@ -282,6 +276,15 @@ class SimilarityRenameDetector {
                                        continue;
                                }
 
+                               if (s == null) {
+                                       try {
+                                               s = hash(OLD, srcEnt);
+                                       } catch (TableFullException tableFull) {
+                                               tableOverflow = true;
+                                               continue SRC;
+                                       }
+                               }
+
                                SimilarityIndex d;
                                try {
                                        d = hash(NEW, dstEnt);