Bug 1132499 - part 2 - convert nsTextEditorState::mValue to be an nsString; r=ehsan
authorNathan Froyd <froydnj@mozilla.com>
Fri, 04 Mar 2016 10:29:01 -0500
changeset 323184 80c48500bf8ff8e02c8d8e16032c05e415120620
parent 323183 abd001def2e83bac50e151aca265a50492305d00
child 323185 a9609f981f978909be000e7025e84eff5209d05c
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1132499, 534785
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 1132499 - part 2 - convert nsTextEditorState::mValue to be an nsString; r=ehsan I don't know the full history here; roc asked about this exact thing in bug 534785 when reviewing the creation of nsTextEditorState. The answer then was "historical reasons" (the original code is hg@1)...maybe to try and save some space? Regardless, since the only thing we do here is convert from/to incoming/outgoing nsStrings, which at least sometimes appear to be causing OOMs, we might as well hold it as an nsString all the time. This change will ideally eliminate allocations, as we'll be able to use nsString's buffer sharing underneath the hood.
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -1913,17 +1913,17 @@ nsTextEditorState::GetValue(nsAString& a
       mCachedValue = aValue;
     } else {
   } else {
     if (!mTextCtrlElement->ValueChanged() || !mValue) {
     } else {
-      aValue = NS_ConvertUTF8toUTF16(*mValue);
+      aValue = *mValue;
 nsTextEditorState::SetValue(const nsAString& aValue, uint32_t aFlags)
   nsAutoString newValue(aValue);
@@ -2143,17 +2143,17 @@ nsTextEditorState::SetValue(const nsAStr
     nsString value;
     if (!value.Assign(newValue, fallible)) {
       return false;
     if (!nsContentUtils::PlatformToDOMLineBreaks(value, fallible)) {
       return false;
-    if (!CopyUTF16toUTF8(value, *mValue, fallible)) {
+    if (!mValue->Assign(value, fallible)) {
       return false;
     // Update the frame display if needed
     if (mBoundFrame) {
--- a/dom/html/nsTextEditorState.h
+++ b/dom/html/nsTextEditorState.h
@@ -289,17 +289,17 @@ private:
   nsITextControlElement* const MOZ_NON_OWNING_REF mTextCtrlElement;
   RefPtr<nsTextInputSelectionImpl> mSelCon;
   RefPtr<RestoreSelectionState> mRestoringSelection;
   nsCOMPtr<nsIEditor> mEditor;
   nsCOMPtr<mozilla::dom::Element> mRootNode;
   nsCOMPtr<mozilla::dom::Element> mPlaceholderDiv;
   nsTextControlFrame* mBoundFrame;
   RefPtr<nsTextInputListener> mTextListener;
-  mozilla::Maybe<nsCString> mValue;
+  mozilla::Maybe<nsString> mValue;
   RefPtr<nsAnonDivObserver> mMutationObserver;
   mutable nsString mCachedValue; // Caches non-hard-wrapped value on a multiline control.
   // mValueBeingSet is available only while SetValue() is requesting to commit
   // composition.  I.e., this is valid only while mIsCommittingComposition is
   // true.  While active composition is being committed, GetValue() needs
   // the latest value which is set by SetValue().  So, this is cache for that.
   nsString mValueBeingSet;
   SelectionProperties mSelectionProperties;