Skip to content

Commit 6bc4e2a

Browse files
Improve DocLineComparator performance #2575
Add a lightweight preliminary check before invoking String.equals(), which avoids unnecessary overhead while preserving correctness for other comparison cases. Fixes #2575
1 parent 2222ff6 commit 6bc4e2a

File tree

2 files changed

+469
-1
lines changed

2 files changed

+469
-1
lines changed

team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DocLineComparator.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,19 @@ public boolean rangesEqual(int thisIndex, IRangeComparator otherComparator, int
183183
int olen= other.getTokenLength(otherIndex);
184184
if (tlen == olen) {
185185
String[] linesToCompare = extract(thisIndex, otherIndex, other, false);
186-
return linesToCompare[0].equals(linesToCompare[1]);
186+
String s1 = linesToCompare[0];
187+
String s2 = linesToCompare[1];
188+
if (s1.isEmpty() && s2.isEmpty()) {
189+
return true;
190+
}
191+
if (s1.isEmpty() || s2.isEmpty()) {
192+
return false;
193+
}
194+
if (s1.length() != s2.length() || s1.charAt(0) != s2.charAt(0)
195+
|| s1.charAt(s1.length() - 1) != s2.charAt(s2.length() - 1)) {
196+
return false;
197+
}
198+
return s1.equals(s2);
187199
} else if (fCompareFilters != null && fCompareFilters.length > 0) {
188200
String[] linesToCompare = extract(thisIndex, otherIndex, other, true);
189201
return linesToCompare[0].equals(linesToCompare[1]);

0 commit comments

Comments
 (0)