optimize caret cloning - do a cheap check first

this makes EditorMultiCaretColumnModeTest.testPageMovementsInteroperateWithLineMovements work much faster,
as position markers in CaretImpl are not created needlessly, and System.gc() in RangeMarkerTree.errMsg is not invoked
This commit is contained in:
Dmitry Batrak
2016-11-10 15:18:44 +03:00
parent 4e6138d804
commit 68513be5ce
@@ -840,6 +840,11 @@ public class CaretImpl extends UserDataHolderBase implements Caret, Dumpable {
public Caret clone(boolean above) {
assertIsDispatchThread();
int lineShift = above ? -1 : 1;
LogicalPosition oldPosition = getLogicalPosition();
int newLine = oldPosition.line + lineShift;
if (newLine < 0 || newLine >= myEditor.getDocument().getLineCount()) {
return null;
}
final CaretImpl clone = cloneWithoutSelection();
final int newSelectionStartOffset;
final int newSelectionEndOffset;
@@ -875,12 +880,6 @@ public class CaretImpl extends UserDataHolderBase implements Caret, Dumpable {
newSelectionStartColumn = -1;
newSelectionEndColumn = -1;
}
LogicalPosition oldPosition = getLogicalPosition();
int newLine = oldPosition.line + lineShift;
if (newLine < 0 || newLine >= myEditor.getDocument().getLineCount()) {
Disposer.dispose(clone);
return null;
}
clone.moveToLogicalPosition(new LogicalPosition(newLine, myLastColumnNumber), false, null, false);
clone.myLastColumnNumber = myLastColumnNumber;
clone.myDesiredX = myDesiredX >= 0 ? myDesiredX : getCurrentX();