Bug 1381080 patch 2 - Encapsulate setting to empty buffer in a new method. r=erahm
authorL. David Baron <dbaron@dbaron.org>
Thu, 20 Jul 2017 15:46:59 -0700
changeset 418719 e5e88978e73540cdd60f7a0374ac74b8fcfe0925
parent 418718 79bc740e42aaeb256202eef44335a563594a7b04
child 418720 235ac09dfdb2412295ac98834fb111e9198b0474
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1381080
milestone56.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 1381080 patch 2 - Encapsulate setting to empty buffer in a new method. r=erahm This is needed for patch 4. MozReview-Commit-ID: 7xKQv37cy5k
xpcom/string/nsTSubstring.cpp
xpcom/string/nsTSubstring.h
--- a/xpcom/string/nsTSubstring.cpp
+++ b/xpcom/string/nsTSubstring.cpp
@@ -683,19 +683,17 @@ nsTSubstring_CharT::SetCapacity(size_typ
 bool
 nsTSubstring_CharT::SetCapacity(size_type aCapacity, const fallible_t&)
 {
   // capacity does not include room for the terminating null char
 
   // if our capacity is reduced to zero, then free our buffer.
   if (aCapacity == 0) {
     ::ReleaseData(mData, mDataFlags);
-    mData = char_traits::sEmptyBuffer;
-    mLength = 0;
-    mDataFlags = DataFlags::TERMINATED;
+    SetToEmptyBuffer();
     return true;
   }
 
   char_type* oldData;
   DataFlags oldFlags;
   if (!MutatePrep(aCapacity, &oldData, &oldFlags)) {
     return false;  // out-of-memory
   }
--- a/xpcom/string/nsTSubstring.h
+++ b/xpcom/string/nsTSubstring.h
@@ -988,19 +988,17 @@ public:
 
   /**
    * If the string uses a shared buffer, this method
    * clears the pointer without releasing the buffer.
    */
   void ForgetSharedBuffer()
   {
     if (mDataFlags & DataFlags::SHARED) {
-      mData = char_traits::sEmptyBuffer;
-      mLength = 0;
-      mDataFlags = DataFlags::TERMINATED;
+      SetToEmptyBuffer();
     }
   }
 
 public:
 
   /**
    * this is public to support automatic conversion of tuple to string
    * base type, which helps avoid converting to nsTAString.
@@ -1078,16 +1076,23 @@ protected:
 #else
 #undef XPCOM_STRING_CONSTRUCTOR_OUT_OF_LINE
     : nsTStringRepr_CharT(aData, aLength, aDataFlags, aClassFlags)
   {
     MOZ_RELEASE_ASSERT(CheckCapacity(aLength), "String is too large.");
   }
 #endif /* DEBUG || FORCE_BUILD_REFCNT_LOGGING */
 
+  void SetToEmptyBuffer()
+  {
+    mData = char_traits::sEmptyBuffer;
+    mLength = 0;
+    mDataFlags = DataFlags::TERMINATED;
+  }
+
   /**
    * this function releases mData and does not change the value of
    * any of its member variables.  in other words, this function acts
    * like a destructor.
    */
   void NS_FASTCALL Finalize();
 
   /**