Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b48cef7 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Optimize TextView#onDraw() a bit

With my previous commit [1], it is now safe to swap reorder nested if
conditions from

  if (imm.hasActiveInputConnection(mTextView)) {
    if (additionalCondition) {
      // do something
    }
  }

to

  if (additionalCondition) {
    if (imm.hasActiveInputConnection(mTextView)) {
      // do something
    }
  }

as IMM#hasActiveInputConnection() is guaranteed to have no side
effect.  Let's do lightweight checks first for better performance.

 [1]: I27f2d66050588c5adc6315160e54486131f3fca2

Bug: 291826769
Test: presubmit
Test: atest CtsInputMethodTestCases
Change-Id: I9b613e71ae05494474c7f1a688c332d0c2836ef9
parent 50cf27b0
Loading
Loading
Loading
Loading
+7 −10
Original line number Diff line number Diff line
@@ -2098,19 +2098,16 @@ public class Editor {
        final int selectionEnd = mTextView.getSelectionEnd();

        final InputMethodState ims = mInputMethodState;
        if (ims != null && ims.mBatchEditNesting == 0) {
        if (ims != null && ims.mBatchEditNesting == 0
                && (ims.mContentChanged || ims.mSelectionModeChanged)) {
            InputMethodManager imm = getInputMethodManager();
            if (imm != null) {
                if (imm.hasActiveInputConnection(mTextView)) {
                    if (ims.mContentChanged || ims.mSelectionModeChanged) {
            if (imm != null && imm.hasActiveInputConnection(mTextView)) {
                // We are in extract mode and the content has changed
                // in some way... just report complete new text to the
                // input method.
                reportExtractedText();
            }
        }
            }
        }

        if (mCorrectionHighlighter != null) {
            mCorrectionHighlighter.draw(canvas, cursorOffsetVertical);