Bug 1457431 - Devirtualize mozInlineSpellChecker::SpellCheckAfterEditorChange. r=masayuki
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Fri, 27 Apr 2018 21:11:31 +0900
changeset 469795 f9fc7f957bb2e648f47a7e2b252b8aa66ca7e960
parent 469794 3eb5075978e313bc6980a44a615863e479b68c05
child 469796 f01311ae4951f5ffb0e26a5a30c48527697e5583
push id9174
push userarchaeopteryx@coole-files.de
push dateMon, 30 Apr 2018 15:33:30 +0000
treeherdermozilla-beta@1b1a8ab75f1f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1457431
milestone61.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 1457431 - Devirtualize mozInlineSpellChecker::SpellCheckAfterEditorChange. r=masayuki It is unnecessary to keep virtual method for mozInlineSpellChecker::SpellCheckAfterEditorChange, so we should remove virtual keyword. MozReview-Commit-ID: 2ry5uhMTFVC
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorBase.h
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/TextEditRules.cpp
editor/spellchecker/nsIInlineSpellChecker.idl
extensions/spellcheck/src/mozInlineSpellChecker.cpp
extensions/spellcheck/src/mozInlineSpellChecker.h
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -4628,31 +4628,32 @@ EditorBase::HandleKeyPressEvent(WidgetKe
       aKeyboardEvent->PreventDefault(); // consumed
       return NS_OK;
   }
   return NS_OK;
 }
 
 nsresult
 EditorBase::HandleInlineSpellCheck(EditAction action,
-                                   Selection* aSelection,
+                                   Selection& aSelection,
                                    nsINode* previousSelectedNode,
                                    uint32_t previousSelectedOffset,
                                    nsINode* aStartContainer,
                                    uint32_t aStartOffset,
                                    nsINode* aEndContainer,
                                    uint32_t aEndOffset)
 {
-  // Have to cast action here because this method is from an IDL
-  return mInlineSpellChecker ? mInlineSpellChecker->SpellCheckAfterEditorChange(
-                                 (int32_t)action, aSelection,
-                                 previousSelectedNode, previousSelectedOffset,
-                                 aStartContainer, aStartOffset, aEndContainer,
-                                 aEndOffset)
-                             : NS_OK;
+  if (!mInlineSpellChecker) {
+    return NS_OK;
+  }
+  return mInlineSpellChecker->SpellCheckAfterEditorChange(
+                                action, aSelection,
+                                previousSelectedNode, previousSelectedOffset,
+                                aStartContainer, aStartOffset, aEndContainer,
+                                aEndOffset);
 }
 
 already_AddRefed<nsIContent>
 EditorBase::FindSelectionRoot(nsINode* aNode)
 {
   nsCOMPtr<nsIContent> rootContent = GetRoot();
   return rootContent.forget();
 }
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -1513,17 +1513,17 @@ public:
   void BeginUpdateViewBatch();
   virtual nsresult EndUpdateViewBatch();
 
   bool GetShouldTxnSetSelection();
 
   virtual nsresult HandleKeyPressEvent(WidgetKeyboardEvent* aKeyboardEvent);
 
   nsresult HandleInlineSpellCheck(EditAction action,
-                                  Selection* aSelection,
+                                  Selection& aSelection,
                                   nsINode* previousSelectedNode,
                                   uint32_t previousSelectedOffset,
                                   nsINode* aStartContainer,
                                   uint32_t aStartOffset,
                                   nsINode* aEndContainer,
                                   uint32_t aEndOffset);
 
   virtual dom::EventTarget* GetDOMEventTarget() = 0;
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -546,17 +546,17 @@ HTMLEditRules::AfterEditInner(EditAction
       ClearCachedStyles();
     }
   }
 
   NS_ENSURE_STATE(mHTMLEditor);
 
   nsresult rv =
     mHTMLEditor->HandleInlineSpellCheck(
-                   aAction, selection,
+                   aAction, *selection,
                    mRangeItem->mStartContainer,
                    mRangeItem->mStartOffset,
                    rangeStartContainer,
                    rangeStartOffset,
                    rangeEndContainer,
                    rangeEndOffset);
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -233,17 +233,17 @@ TextEditRules::AfterEdit(EditAction aAct
   NS_PRECONDITION(mActionNesting>0, "bad action nesting!");
   if (!--mActionNesting) {
     NS_ENSURE_STATE(mTextEditor);
     RefPtr<Selection> selection = mTextEditor->GetSelection();
     NS_ENSURE_STATE(selection);
 
     NS_ENSURE_STATE(mTextEditor);
     nsresult rv =
-      mTextEditor->HandleInlineSpellCheck(aAction, selection,
+      mTextEditor->HandleInlineSpellCheck(aAction, *selection,
                                           mCachedSelectionNode,
                                           mCachedSelectionOffset,
                                           nullptr, 0, nullptr, 0);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // no longer uses mCachedSelectionNode, so release it.
     mCachedSelectionNode = nullptr;
 
--- a/editor/spellchecker/nsIInlineSpellChecker.idl
+++ b/editor/spellchecker/nsIInlineSpellChecker.idl
@@ -5,41 +5,26 @@
 
 #include "nsISupports.idl"
 #include "domstubs.idl"
 
 interface nsISelection;
 interface nsIEditor;
 interface nsIEditorSpellCheck;
 
-%{ C++
-class nsINode;
-%}
-[ptr] native nsINodePtr(nsINode);
-
 [scriptable, uuid(b7b7a77c-40c4-4196-b0b7-b0338243b3fe)]
 interface nsIInlineSpellChecker : nsISupports
 {
   readonly attribute nsIEditorSpellCheck spellChecker;
 
   void init(in nsIEditor aEditor);
   void cleanup(in boolean aDestroyingFrames);
 
   attribute boolean enableRealTimeSpell;
 
-  [noscript] void spellCheckAfterEditorChange(
-                    in long aAction,
-                    in nsISelection aSelection,
-                    in nsINodePtr aPreviousSelectedNode,
-                    in unsigned long aPreviousSelectedOffset,
-                    in nsINodePtr aStartNode,
-                    in unsigned long aStartOffset,
-                    in nsINodePtr aEndNode,
-                    in unsigned long aEndOffset);
-
   void spellCheckRange(in nsIDOMRange aSelection);
 
   nsIDOMRange getMisspelledWord(in nsIDOMNode aNode, in long aOffset);
   void replaceWord(in nsIDOMNode aNode, in long aOffset, in AString aNewword);
   void addWordToDictionary(in AString aWord);
   void removeWordFromDictionary(in AString aWord);
 
   void ignoreWord(in AString aWord);
--- a/extensions/spellcheck/src/mozInlineSpellChecker.cpp
+++ b/extensions/spellcheck/src/mozInlineSpellChecker.cpp
@@ -856,39 +856,36 @@ mozInlineSpellChecker::NotifyObservers(c
 //
 //    Called by the editor when nearly anything happens to change the content.
 //
 //    The start and end positions specify a range for the thing that happened,
 //    but these are usually nullptr, even when you'd think they would be useful
 //    because you want the range (for example, pasting). We ignore them in
 //    this case.
 
-NS_IMETHODIMP
+nsresult
 mozInlineSpellChecker::SpellCheckAfterEditorChange(
-    int32_t aAction, nsISelection *aSelection,
+    EditAction aAction, Selection& aSelection,
     nsINode *aPreviousSelectedNode, uint32_t aPreviousSelectedOffset,
     nsINode *aStartNode, uint32_t aStartOffset,
     nsINode *aEndNode, uint32_t aEndOffset)
 {
   nsresult rv;
-  NS_ENSURE_ARG_POINTER(aSelection);
   if (!mSpellCheck)
     return NS_OK; // disabling spell checking is not an error
 
   // this means something has changed, and we never check the current word,
   // therefore, we should spellcheck for subsequent caret navigations
   mNeedsCheckAfterNavigation = true;
 
-  RefPtr<Selection> selection = aSelection->AsSelection();
-
   // the anchor node is the position of the caret
   auto status = MakeUnique<mozInlineSpellStatus>(this);
-  rv = status->InitForEditorChange((EditAction)aAction,
-                                   selection->GetAnchorNode(),
-                                   selection->AnchorOffset(),
+  rv = status->InitForEditorChange(aAction,
+                                   aSelection.GetAnchorNode(),
+                                   aSelection.AnchorOffset(),
                                    aPreviousSelectedNode,
                                    aPreviousSelectedOffset,
                                    aStartNode, aStartOffset,
                                    aEndNode, aEndOffset);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = ScheduleSpellCheck(Move(status));
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/extensions/spellcheck/src/mozInlineSpellChecker.h
+++ b/extensions/spellcheck/src/mozInlineSpellChecker.h
@@ -252,16 +252,25 @@ public:
 
   nsresult ResumeCheck(mozilla::UniquePtr<mozInlineSpellStatus>&& aStatus);
 
   // Those methods are called when mTextEditor splits a node or joins the
   // given nodes.
   void DidSplitNode(nsINode* aExistingRightNode, nsINode* aNewLeftNode);
   void DidJoinNodes(nsINode& aRightNode, nsINode& aLeftNode);
 
+  nsresult SpellCheckAfterEditorChange(mozilla::EditAction aAction,
+                                       mozilla::dom::Selection& aSelection,
+                                       nsINode* aPreviousSelectedNode,
+                                       uint32_t aPreviousSelectedOffset,
+                                       nsINode* aStartNode,
+                                       uint32_t aStartOffset,
+                                       nsINode* aEndNode,
+                                       uint32_t aEndOffset);
+
 protected:
   virtual ~mozInlineSpellChecker();
 
   // called when async nsIEditorSpellCheck methods complete
   nsresult EditorSpellCheckInited();
   nsresult CurrentDictionaryUpdated();
 
   // track the number of pending spell checks and async operations that may lead