diff options
author | 2014-05-30 09:30:57 +0000 | |
---|---|---|
committer | 2014-05-30 09:30:57 +0000 | |
commit | b95e3bdf221cc7580bb3514b9ecb2f3980127382 (patch) | |
tree | 3a6455ac31422c92aa1b75b55d7f02e88f7a9bf2 /java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java | |
parent | f41f7a185bd1a3de9e41369520d181f9177c9f40 (diff) | |
parent | fa0e76dde606c288e4df20b779995cbce3b187fb (diff) | |
download | latinime-b95e3bdf221cc7580bb3514b9ecb2f3980127382.tar.gz latinime-b95e3bdf221cc7580bb3514b9ecb2f3980127382.tar.xz latinime-b95e3bdf221cc7580bb3514b9ecb2f3980127382.zip |
am fa0e76dd: Limit recapitalization for reasonable performance.
* commit 'fa0e76dde606c288e4df20b779995cbce3b187fb':
Limit recapitalization for reasonable performance.
Diffstat (limited to 'java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 4fac5ed2d..d4833f5fc 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -1139,15 +1139,21 @@ public final class InputLogic { if (!mConnection.hasSelection()) { return; // No selection } + final int selectionStart = mConnection.getExpectedSelectionStart(); + final int selectionEnd = mConnection.getExpectedSelectionEnd(); + final int numCharsSelected = selectionEnd - selectionStart; + if (numCharsSelected > Constants.MAX_CHARACTERS_FOR_RECAPITALIZATION) { + // We bail out if we have too many characters for performance reasons. We don't want + // to suck possibly multiple-megabyte data. + return; + } // If we have a recapitalize in progress, use it; otherwise, create a new one. if (!mRecapitalizeStatus.isActive() - || !mRecapitalizeStatus.isSetAt(mConnection.getExpectedSelectionStart(), - mConnection.getExpectedSelectionEnd())) { + || !mRecapitalizeStatus.isSetAt(selectionStart, selectionEnd)) { final CharSequence selectedText = mConnection.getSelectedText(0 /* flags, 0 for no styles */); if (TextUtils.isEmpty(selectedText)) return; // Race condition with the input connection - mRecapitalizeStatus.initialize(mConnection.getExpectedSelectionStart(), - mConnection.getExpectedSelectionEnd(), selectedText.toString(), + mRecapitalizeStatus.initialize(selectionStart, selectionEnd, selectedText.toString(), settingsValues.mLocale, settingsValues.mSpacingAndPunctuations.mSortedWordSeparators); // We trim leading and trailing whitespace. @@ -1155,11 +1161,8 @@ public final class InputLogic { } mConnection.finishComposingText(); mRecapitalizeStatus.rotate(); - final int numCharsDeleted = mConnection.getExpectedSelectionEnd() - - mConnection.getExpectedSelectionStart(); - mConnection.setSelection(mConnection.getExpectedSelectionEnd(), - mConnection.getExpectedSelectionEnd()); - mConnection.deleteSurroundingText(numCharsDeleted, 0); + mConnection.setSelection(selectionEnd, selectionEnd); + mConnection.deleteSurroundingText(numCharsSelected, 0); mConnection.commitText(mRecapitalizeStatus.getRecapitalizedString(), 0); mConnection.setSelection(mRecapitalizeStatus.getNewCursorStart(), mRecapitalizeStatus.getNewCursorEnd()); |