Bug 732951. r=bsmedberg, a=akeybl
authorMats Palmgren <matspal@gmail.com>
Tue, 20 Mar 2012 19:02:38 +0100
changeset 92072 9d0f242dd27767d211ac36dd6b379d245c48d19a
parent 92071 008838e028ba05a11acc45c3ca81829619432aab
child 92073 89759fa12b9295daa63df7767b4c60891a1df671
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg, akeybl
bugs732951
milestone13.0a2
Bug 732951. r=bsmedberg, a=akeybl
xpcom/string/public/nsTSubstring.h
xpcom/string/src/nsTSubstring.cpp
--- a/xpcom/string/public/nsTSubstring.h
+++ b/xpcom/string/public/nsTSubstring.h
@@ -467,17 +467,17 @@ class nsTSubstring_CharT
          * the length of the string. Also ensures that the buffer is mutable.
          *
          * @returns true on success
          *          false on out-of-memory, or if requesting a size bigger
          *                   than a string can hold (2^31 chars).
          */
       bool NS_FASTCALL SetCapacity( size_type newCapacity );
 
-      void NS_FASTCALL SetLength( size_type newLength );
+      bool NS_FASTCALL SetLength( size_type newLength );
 
       void Truncate( size_type newLength = 0 )
         {
           NS_ASSERTION(newLength <= mLength, "Truncate cannot make string longer");
           SetLength(newLength);
         }
 
 
--- a/xpcom/string/src/nsTSubstring.cpp
+++ b/xpcom/string/src/nsTSubstring.cpp
@@ -284,26 +284,19 @@ nsTSubstring_CharT::EnsureMutable( size_
   {
     if (newLen == size_type(-1) || newLen == mLength)
       {
         if (mFlags & (F_FIXED | F_OWNED))
           return true;
         if ((mFlags & F_SHARED) && !nsStringBuffer::FromData(mData)->IsReadonly())
           return true;
 
-        // promote to a shared string buffer
-        char_type* prevData = mData;
-        Assign(mData, mLength);
-        return mData != prevData;
+        newLen = mLength;
       }
-    else
-      {
-        SetLength(newLen);
-        return mLength == newLen;
-      }
+    return SetLength(newLen);
   }
 
 // ---------------------------------------------------------------------------
 
   // This version of Assign is optimized for single-character assignment.
 void
 nsTSubstring_CharT::Assign( char_type c )
   {
@@ -568,21 +561,24 @@ nsTSubstring_CharT::SetCapacity( size_ty
         // always null-terminate here, even if the buffer got longer.  this is
         // for backwards compat with the old string implementation.
         mData[capacity] = char_type(0);
       }
 
     return true;
   }
 
-void
+bool
 nsTSubstring_CharT::SetLength( size_type length )
   {
-    if (SetCapacity(length))
-      mLength = length;
+    if (!SetCapacity(length))
+      return false;
+
+    mLength = length;
+    return true;
   }
 
 void
 nsTSubstring_CharT::SetIsVoid( bool val )
   {
     if (val)
       {
         Truncate();