mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: extract method
This commit is contained in:
@@ -21,7 +21,6 @@ import com.intellij.diff.util.MergeRange;
|
||||
import com.intellij.diff.util.Range;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import gnu.trove.TIntArrayList;
|
||||
@@ -306,7 +305,7 @@ public class ByLine {
|
||||
private static FairDiffIterable compareSmart(@NotNull List<Line> lines1,
|
||||
@NotNull List<Line> lines2,
|
||||
@NotNull ProgressIndicator indicator) {
|
||||
int threshold = Registry.intValue("diff.unimportant.line.char.count");
|
||||
int threshold = ComparisonUtil.getUnimportantLineCharCount();
|
||||
if (threshold == 0) return diff(lines1, lines2, indicator);
|
||||
|
||||
Pair<List<Line>, TIntArrayList> bigLines1 = getBigLines(lines1, threshold);
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.intellij.diff.comparison.iterables.FairDiffIterable;
|
||||
import com.intellij.diff.util.Range;
|
||||
import com.intellij.diff.util.Side;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -215,19 +214,17 @@ abstract class ChunkOptimizer<T> {
|
||||
* bad: "ABooYZ AB[uuYZ AB]zzYZ" - "ABooYZ AB[]zzYZ"
|
||||
*/
|
||||
public static class LineChunkOptimizer extends ChunkOptimizer<Line> {
|
||||
private final int myThreshold;
|
||||
|
||||
public LineChunkOptimizer(@NotNull List<Line> lines1,
|
||||
@NotNull List<Line> lines2,
|
||||
@NotNull FairDiffIterable changes,
|
||||
@NotNull ProgressIndicator indicator) {
|
||||
super(lines1, lines2, changes, indicator);
|
||||
myThreshold = Registry.intValue("diff.unimportant.line.char.count");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getShift(@NotNull Side touchSide, int equalForward, int equalBackward, @NotNull Range range1, @NotNull Range range2) {
|
||||
Integer shift;
|
||||
int threshold = ComparisonUtil.getUnimportantLineCharCount();
|
||||
|
||||
shift = getUnchangedBoundaryShift(touchSide, equalForward, equalBackward, range1, range2, 0);
|
||||
if (shift != null) return shift;
|
||||
@@ -235,10 +232,10 @@ abstract class ChunkOptimizer<T> {
|
||||
shift = getChangedBoundaryShift(touchSide, equalForward, equalBackward, range1, range2, 0);
|
||||
if (shift != null) return shift;
|
||||
|
||||
shift = getUnchangedBoundaryShift(touchSide, equalForward, equalBackward, range1, range2, myThreshold);
|
||||
shift = getUnchangedBoundaryShift(touchSide, equalForward, equalBackward, range1, range2, threshold);
|
||||
if (shift != null) return shift;
|
||||
|
||||
shift = getChangedBoundaryShift(touchSide, equalForward, equalBackward, range1, range2, myThreshold);
|
||||
shift = getChangedBoundaryShift(touchSide, equalForward, equalBackward, range1, range2, threshold);
|
||||
if (shift != null) return shift;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -15,11 +15,14 @@
|
||||
*/
|
||||
package com.intellij.diff.comparison;
|
||||
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ComparisonUtil {
|
||||
private static final int UNIMPORTANT_LINE_CHAR_COUNT = Registry.intValue("diff.unimportant.line.char.count");
|
||||
|
||||
@Contract(pure = true)
|
||||
public static boolean isEquals(@NotNull CharSequence text1, @NotNull CharSequence text2, @NotNull ComparisonPolicy policy) {
|
||||
switch (policy) {
|
||||
@@ -64,4 +67,8 @@ public class ComparisonUtil {
|
||||
if (lastLine1) return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getUnimportantLineCharCount() {
|
||||
return UNIMPORTANT_LINE_CHAR_COUNT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.intellij.diff.util.ThreeSide
|
||||
import com.intellij.openapi.editor.Document
|
||||
import com.intellij.openapi.editor.impl.DocumentImpl
|
||||
import com.intellij.openapi.util.Couple
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
|
||||
class ComparisonUtilAutoTest : DiffTestCase() {
|
||||
@@ -516,8 +515,8 @@ class ComparisonUtilAutoTest : DiffTestCase() {
|
||||
// in non-squashed blocks non-trimmed elements are possible
|
||||
if (allowNonSquashed) {
|
||||
if (policy != ComparisonPolicy.IGNORE_WHITESPACES) return
|
||||
if (countNonWhitespaceCharacters(line1) <= Registry.get("diff.unimportant.line.char.count").asInteger()) return
|
||||
if (countNonWhitespaceCharacters(line2) <= Registry.get("diff.unimportant.line.char.count").asInteger()) return
|
||||
if (countNonWhitespaceCharacters(line1) <= ComparisonUtil.getUnimportantLineCharCount()) return
|
||||
if (countNonWhitespaceCharacters(line2) <= ComparisonUtil.getUnimportantLineCharCount()) return
|
||||
}
|
||||
|
||||
assertFalse(MANAGER.isEquals(line1, line2, policy))
|
||||
|
||||
@@ -519,6 +519,7 @@ diff.verify.iterable.description=Enable diff algorithm self check
|
||||
diff.verify.iterable.restartRequired=true
|
||||
diff.unimportant.line.char.count=3
|
||||
diff.unimportant.line.char.count.description=Threshold number of non-space characters to mark line as unimportant
|
||||
diff.unimportant.line.char.count.restartRequired=true
|
||||
diff.maximum.changes.array.size=10000000
|
||||
diff.maximum.changes.array.size.restartRequired=true
|
||||
diff.divider.repainting.disable.blitting=true
|
||||
|
||||
Reference in New Issue
Block a user