Bug 1408290 - Avoid calling nsINode::IndexOf() in HTMLEditRules::CheckForInvisibleBR(); r=masayuki
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 13 Oct 2017 02:15:01 -0400
changeset 386151 7a1b3a7815c8296cf41aee8001d6e2084f52ba50
parent 386150 ed52576868a90633c917b4a0adbdd407833bec24
child 386152 38330dd0d9e5e297b396e760c2997c86a1e64a59
push id32676
push userarchaeopteryx@coole-files.de
push dateFri, 13 Oct 2017 21:38:18 +0000
treeherdermozilla-central@a31334a65a1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1408290
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1408290 - Avoid calling nsINode::IndexOf() in HTMLEditRules::CheckForInvisibleBR(); r=masayuki
editor/libeditor/HTMLEditRules.cpp
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -5144,18 +5144,23 @@ HTMLEditRules::CheckForInvisibleBR(Eleme
     nsCOMPtr<nsIContent> rightmostNode =
       mHTMLEditor->GetRightmostChild(&aBlock, true);
 
     if (!rightmostNode) {
       return nullptr;
     }
 
     testNode = rightmostNode->GetParentNode();
+    // Since rightmostNode is always the last child, its index is equal to the
+    // child count, so instead of IndexOf() we use the faster GetChildCount(),
+    // and assert the equivalence below.
+    testOffset = testNode->GetChildCount();
+
     // Use offset + 1, so last node is included in our evaluation
-    testOffset = testNode->IndexOf(rightmostNode) + 1;
+    MOZ_ASSERT(testNode->IndexOf(rightmostNode) + 1 == testOffset);
   } else if (aOffset) {
     testNode = &aBlock;
     // We'll check everything to the left of the input position
     testOffset = aOffset;
   } else {
     return nullptr;
   }