Bug 1470861: Remove useless code. r?mats draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 25 Jun 2018 13:17:02 +0200
changeset 810141 ed707edc3378874c36a9bbf1bfb0ea4e678b941b
parent 810140 302ab388085afe8f56413eecefd7514bc44536f3
child 810142 8137a3f6cb3ab284567e1bc095d5481e33768307
push id113905
push userbmo:emilio@crisal.io
push dateMon, 25 Jun 2018 12:31:46 +0000
reviewersmats
bugs1470861
milestone62.0a1
Bug 1470861: Remove useless code. r?mats We're throwing away the computation when aContinueOk is true, so we can remove that call. Removing that call removes the last usage of aContinueOk, so remove that handling as well. MozReview-Commit-ID: E3sogickWp9
toolkit/components/find/nsFind.cpp
toolkit/components/find/nsFind.h
--- a/toolkit/components/find/nsFind.cpp
+++ b/toolkit/components/find/nsFind.cpp
@@ -725,61 +725,45 @@ nsFind::SetEntireWord(bool aEntireWord)
 // union of a one-byte string or a two-byte string. Single and double strings
 // are intermixed in the dom. We don't have string classes which can deal with
 // intermixed strings, so all the handling is done explicitly here.
 
 nsresult
 nsFind::NextNode(State& aState,
                  nsRange* aSearchRange,
                  nsRange* aStartPoint,
-                 nsRange* aEndPoint,
-                 bool aContinueOk)
+                 nsRange* aEndPoint)
 {
   nsresult rv;
 
   nsCOMPtr<nsIContent> content;
 
-  if (!aState.mIterator || aContinueOk) {
+  if (!aState.mIterator) {
     // If we are continuing, that means we have a match in progress. In that
     // case, we want to continue from the end point (where we are now) to the
     // beginning/end of the search range.
     nsCOMPtr<nsINode> startNode;
     nsCOMPtr<nsINode> endNode;
     uint32_t startOffset, endOffset;
-    if (aContinueOk) {
-      DEBUG_FIND_PRINTF("Match in progress: continuing past endpoint\n");
-      if (mFindBackward) {
-        startNode = aSearchRange->GetStartContainer();
-        startOffset = aSearchRange->StartOffset();
-        endNode = aEndPoint->GetStartContainer();
-        endOffset = aEndPoint->StartOffset();
-      } else { // forward
-        startNode = aEndPoint->GetEndContainer();
-        startOffset = aEndPoint->EndOffset();
-        endNode = aSearchRange->GetEndContainer();
-        endOffset = aSearchRange->EndOffset();
-      }
-    } else { // Normal, not continuing
-      if (mFindBackward) {
-        startNode = aSearchRange->GetStartContainer();
-        startOffset = aSearchRange->StartOffset();
-        endNode = aStartPoint->GetEndContainer();
-        endOffset = aStartPoint->EndOffset();
-        // XXX Needs work: Problem with this approach: if there is a match which
-        // starts just before the current selection and continues into the
-        // selection, we will miss it, because our search algorithm only starts
-        // searching from the end of the word, so we would have to search the
-        // current selection but discount any matches that fall entirely inside
-        // it.
-      } else { // forward
-        startNode = aStartPoint->GetStartContainer();
-        startOffset = aStartPoint->StartOffset();
-        endNode = aEndPoint->GetEndContainer();
-        endOffset = aEndPoint->EndOffset();
-      }
+    if (mFindBackward) {
+      startNode = aSearchRange->GetStartContainer();
+      startOffset = aSearchRange->StartOffset();
+      endNode = aStartPoint->GetEndContainer();
+      endOffset = aStartPoint->EndOffset();
+      // XXX Needs work: Problem with this approach: if there is a match which
+      // starts just before the current selection and continues into the
+      // selection, we will miss it, because our search algorithm only starts
+      // searching from the end of the word, so we would have to search the
+      // current selection but discount any matches that fall entirely inside
+      // it.
+    } else { // forward
+      startNode = aStartPoint->GetStartContainer();
+      startOffset = aStartPoint->StartOffset();
+      endNode = aEndPoint->GetEndContainer();
+      endOffset = aEndPoint->EndOffset();
     }
 
     rv = InitIterator(aState,
                       startNode,
                       static_cast<int32_t>(startOffset),
                       endNode,
                       static_cast<int32_t>(endOffset));
     NS_ENSURE_SUCCESS(rv, rv);
@@ -872,17 +856,17 @@ nsFind::PeekNextChar(State& aState,
   // We need to restore the necessary state before this function returns.
   StateRestorer restorer(aState);
 
   const nsTextFragment *frag;
   int32_t fragLen;
 
   // Loop through non-block nodes until we find one that's not empty.
   do {
-    NextNode(aState, aSearchRange, aStartPoint, aEndPoint, false);
+    NextNode(aState, aSearchRange, aStartPoint, aEndPoint);
 
     // Get the text content:
     nsCOMPtr<nsIContent> tc = do_QueryInterface(aState.mIterNode);
 
     // Get the block parent.
     nsIContent* blockParent = GetBlockParent(aState.mIterNode);
     if (!blockParent)
       return L'\0';
@@ -1007,25 +991,18 @@ nsFind::Find(const char16_t* aPatText, n
 
   while (1) {
     DEBUG_FIND_PRINTF("Loop ...\n");
 
     // If this is our first time on a new node, reset the pointers:
     if (!frag) {
 
       tc = nullptr;
-      NextNode(state, aSearchRange, aStartPoint, aEndPoint, false);
+      NextNode(state, aSearchRange, aStartPoint, aEndPoint);
       if (!state.mIterNode) { // Out of nodes
-        // Are we in the middle of a match? If so, try again with continuation.
-        //
-        // FIXME(emilio): If we return here unconditionally, why is this useful?
-        // Shouldn't we check `state.mIterNode` again?
-        if (matchAnchorNode) {
-          NextNode(state, aSearchRange, aStartPoint, aEndPoint, true);
-        }
         return NS_OK;
       }
 
       // We have a new text content. If its block parent is different from the
       // block parent of the last text content, then we need to clear the match
       // since we don't want to find across block boundaries.
       nsIContent* blockParent = GetBlockParent(state.mIterNode);
       DEBUG_FIND_PRINTF("New node: old blockparent = %p, new = %p\n",
--- a/toolkit/components/find/nsFind.h
+++ b/toolkit/components/find/nsFind.h
@@ -48,18 +48,17 @@ protected:
   struct State;
   class StateRestorer;
   nsIContent* GetBlockParent(nsINode* aNode);
 
   // Move in the right direction for our search:
   nsresult NextNode(State&,
                     nsRange* aSearchRange,
                     nsRange* aStartPoint,
-                    nsRange* aEndPoint,
-                    bool aContinueOk);
+                    nsRange* aEndPoint);
 
   // Get the first character from the next node (last if mFindBackward).
   //
   // This will mutate the state, but then restore it afterwards.
   char16_t PeekNextChar(State&,
                         nsRange* aSearchRange,
                         nsRange* aStartPoint,
                         nsRange* aEndPoint);