[tor-commits] [tor-browser/esr24] Bug 1007940 - Improve the performance of editor initialization. r=bzbarsky, a=lmandel

mikeperry at torproject.org mikeperry at torproject.org
Fri Aug 29 05:26:41 UTC 2014


commit 1bef29ba36ea5c8359617b3df4e68b76b4b50b98
Author: Ehsan Akhgari <ehsan at mozilla.com>
Date:   Fri May 9 17:02:29 2014 -0400

    Bug 1007940 - Improve the performance of editor initialization. r=bzbarsky, a=lmandel
---
 editor/libeditor/html/nsHTMLEditRules.cpp   |   32 +++++++++++++++++---------
 editor/libeditor/html/nsHTMLEditRules.h     |    2 ++
 editor/libeditor/html/nsHTMLEditor.cpp      |    7 +++---
 editor/libeditor/text/nsPlaintextEditor.cpp |    8 +++----
 editor/libeditor/text/nsTextEditRules.cpp   |   33 +++++++++++++++++++--------
 editor/libeditor/text/nsTextEditRules.h     |    2 ++
 6 files changed, 56 insertions(+), 28 deletions(-)

diff --git a/editor/libeditor/html/nsHTMLEditRules.cpp b/editor/libeditor/html/nsHTMLEditRules.cpp
index 04e94ea..599682e 100644
--- a/editor/libeditor/html/nsHTMLEditRules.cpp
+++ b/editor/libeditor/html/nsHTMLEditRules.cpp
@@ -169,16 +169,25 @@ class nsEditableTextFunctor : public nsBoolDomIterFunctor
  *  Constructor/Destructor 
  ********************************************************/
 
-nsHTMLEditRules::nsHTMLEditRules() : 
-mDocChangeRange(nullptr)
-,mListenerEnabled(true)
-,mReturnInEmptyLIKillsList(true)
-,mDidDeleteSelection(false)
-,mDidRangedDelete(false)
-,mRestoreContentEditableCount(false)
-,mUtilRange(nullptr)
-,mJoinOffset(0)
+nsHTMLEditRules::nsHTMLEditRules()
 {
+  InitFields();
+}
+
+void
+nsHTMLEditRules::InitFields()
+{
+  mHTMLEditor = nullptr;
+  mDocChangeRange = nullptr;
+  mListenerEnabled = true;
+  mReturnInEmptyLIKillsList = true;
+  mDidDeleteSelection = false;
+  mDidRangedDelete = false;
+  mRestoreContentEditableCount = false;
+  mUtilRange = nullptr;
+  mJoinOffset = 0;
+  mNewBlock = nullptr;
+  mRangeItem = new nsRangeStore();
   // populate mCachedStyles
   mCachedStyles[0] = StyleCache(nsEditProperty::b, EmptyString(), EmptyString());
   mCachedStyles[1] = StyleCache(nsEditProperty::i, EmptyString(), EmptyString());
@@ -199,7 +208,6 @@ mDocChangeRange(nullptr)
   mCachedStyles[16] = StyleCache(nsEditProperty::cssBackgroundColor, EmptyString(), EmptyString());
   mCachedStyles[17] = StyleCache(nsEditProperty::sub, EmptyString(), EmptyString());
   mCachedStyles[18] = StyleCache(nsEditProperty::sup, EmptyString(), EmptyString());
-  mRangeItem = new nsRangeStore();
 }
 
 nsHTMLEditRules::~nsHTMLEditRules()
@@ -229,9 +237,11 @@ NS_IMPL_QUERY_INTERFACE_INHERITED1(nsHTMLEditRules, nsTextEditRules, nsIEditActi
 NS_IMETHODIMP
 nsHTMLEditRules::Init(nsPlaintextEditor *aEditor)
 {
+  InitFields();
+
   mHTMLEditor = static_cast<nsHTMLEditor*>(aEditor);
   nsresult res;
-  
+
   // call through to base class Init 
   res = nsTextEditRules::Init(aEditor);
   NS_ENSURE_SUCCESS(res, res);
diff --git a/editor/libeditor/html/nsHTMLEditRules.h b/editor/libeditor/html/nsHTMLEditRules.h
index 28bf20c..5d12c4d 100644
--- a/editor/libeditor/html/nsHTMLEditRules.h
+++ b/editor/libeditor/html/nsHTMLEditRules.h
@@ -125,6 +125,8 @@ protected:
     kBlockEnd
   };
 
+  void InitFields();
+
   // nsHTMLEditRules implementation methods
   nsresult WillInsert(nsISelection *aSelection, bool *aCancel);
   nsresult WillInsertText(  EditAction aAction,
diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp
index 2bc2ce6..9ed79d5 100644
--- a/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/editor/libeditor/html/nsHTMLEditor.cpp
@@ -485,9 +485,10 @@ nsHTMLEditor::SetFlags(uint32_t aFlags)
 NS_IMETHODIMP
 nsHTMLEditor::InitRules()
 {
-  MOZ_ASSERT(!mRules);
-  // instantiate the rules for the html editor
-  mRules = new nsHTMLEditRules();
+  if (!mRules) {
+    // instantiate the rules for the html editor
+    mRules = new nsHTMLEditRules();
+  }
   return mRules->Init(static_cast<nsPlaintextEditor*>(this));
 }
 
diff --git a/editor/libeditor/text/nsPlaintextEditor.cpp b/editor/libeditor/text/nsPlaintextEditor.cpp
index 39db37c..f5e7053 100644
--- a/editor/libeditor/text/nsPlaintextEditor.cpp
+++ b/editor/libeditor/text/nsPlaintextEditor.cpp
@@ -121,7 +121,6 @@ NS_IMETHODIMP nsPlaintextEditor::Init(nsIDOMDocument *aDoc,
   nsresult res = NS_OK, rulesRes = NS_OK;
   if (mRules) {
     mRules->DetachEditor();
-    mRules = nullptr;
   }
   
   if (1)
@@ -315,9 +314,10 @@ nsPlaintextEditor::UpdateMetaCharset(nsIDOMDocument* aDocument,
 
 NS_IMETHODIMP nsPlaintextEditor::InitRules()
 {
-  MOZ_ASSERT(!mRules);
-  // instantiate the rules for this text editor
-  mRules = new nsTextEditRules();
+  if (!mRules) {
+    // instantiate the rules for this text editor
+    mRules = new nsTextEditRules();
+  }
   return mRules->Init(this);
 }
 
diff --git a/editor/libeditor/text/nsTextEditRules.cpp b/editor/libeditor/text/nsTextEditRules.cpp
index aaba83d..d3852b7 100644
--- a/editor/libeditor/text/nsTextEditRules.cpp
+++ b/editor/libeditor/text/nsTextEditRules.cpp
@@ -56,17 +56,28 @@ using namespace mozilla;
  ********************************************************/
 
 nsTextEditRules::nsTextEditRules()
-: mEditor(nullptr)
-, mPasswordText()
-, mPasswordIMEText()
-, mPasswordIMEIndex(0)
-, mActionNesting(0)
-, mLockRulesSniffing(false)
-, mDidExplicitlySetInterline(false)
-, mTheAction(EditAction::none)
-, mLastStart(0)
-, mLastLength(0)
 {
+  InitFields();
+}
+
+void
+nsTextEditRules::InitFields()
+{
+  mEditor = nullptr;
+  mPasswordText.Truncate();
+  mPasswordIMEText.Truncate();
+  mPasswordIMEIndex = 0;
+  mBogusNode = nullptr;
+  mCachedSelectionNode = nullptr;
+  mCachedSelectionOffset = 0;
+  mActionNesting = 0;
+  mLockRulesSniffing = false;
+  mDidExplicitlySetInterline = false;
+  mDeleteBidiImmediately = false;
+  mTheAction = EditAction::none;
+  mTimer = nullptr;
+  mLastStart = 0;
+  mLastLength = 0;
 }
 
 nsTextEditRules::~nsTextEditRules()
@@ -101,6 +112,8 @@ nsTextEditRules::Init(nsPlaintextEditor *aEditor)
 {
   if (!aEditor) { return NS_ERROR_NULL_POINTER; }
 
+  InitFields();
+
   mEditor = aEditor;  // we hold a non-refcounted reference back to our editor
   nsCOMPtr<nsISelection> selection;
   mEditor->GetSelection(getter_AddRefs(selection));
diff --git a/editor/libeditor/text/nsTextEditRules.h b/editor/libeditor/text/nsTextEditRules.h
index 4dfed8a..3db6463 100644
--- a/editor/libeditor/text/nsTextEditRules.h
+++ b/editor/libeditor/text/nsTextEditRules.h
@@ -99,6 +99,8 @@ public:
 
 protected:
 
+  void InitFields();
+
   // nsTextEditRules implementation methods
   nsresult WillInsertText(  EditAction aAction,
                             mozilla::Selection* aSelection,





More information about the tor-commits mailing list