diff --git a/mozilla/string/obsolete/nsString.cpp b/mozilla/string/obsolete/nsString.cpp index 21e016f5016..c64c7b9340f 100644 --- a/mozilla/string/obsolete/nsString.cpp +++ b/mozilla/string/obsolete/nsString.cpp @@ -195,18 +195,26 @@ void nsCString::SetLength(PRUint32 anIndex) { /** - * Call this method if you want to force the string to a certain capacity - * @update gess 1/4/99 - * @param aLength -- contains new length for mStr + * Call this method if you want to force the string to a certain capacity; + * |SetCapacity(0)| discards associated storage. + * + * @param aNewCapacity -- desired minimum capacity */ -void nsCString::SetCapacity(PRUint32 aLength) { - if(aLength) { - if(aLength>mCapacity) { - GrowCapacity(*this,aLength); - } - AddNullTerminator(*this); +void +nsCString::SetCapacity( PRUint32 aNewCapacity ) + { + if ( aNewCapacity ) + { + if( aNewCapacity > mCapacity ) + GrowCapacity(*this,aNewCapacity); + AddNullTerminator(*this); + } + else + { + nsStr::Destroy(*this); + nsStr::Initialize(*this, eOneByte); + } } -} /********************************************************************** Accessor methods... @@ -742,7 +750,6 @@ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const { PRBool done=PR_FALSE; while((cpmCapacity) { - GrowCapacity(*this,aLength); - } - AddNullTerminator(*this); +void +nsString::SetCapacity( PRUint32 aNewCapacity ) + { + if ( aNewCapacity ) + { + if( aNewCapacity > mCapacity ) + GrowCapacity(*this, aNewCapacity); + AddNullTerminator(*this); + } + else + { + nsStr::Destroy(*this); + nsStr::Initialize(*this, eTwoByte); + } } -} /********************************************************************** Accessor methods... diff --git a/mozilla/xpcom/ds/nsString.cpp b/mozilla/xpcom/ds/nsString.cpp index 21e016f5016..c64c7b9340f 100644 --- a/mozilla/xpcom/ds/nsString.cpp +++ b/mozilla/xpcom/ds/nsString.cpp @@ -195,18 +195,26 @@ void nsCString::SetLength(PRUint32 anIndex) { /** - * Call this method if you want to force the string to a certain capacity - * @update gess 1/4/99 - * @param aLength -- contains new length for mStr + * Call this method if you want to force the string to a certain capacity; + * |SetCapacity(0)| discards associated storage. + * + * @param aNewCapacity -- desired minimum capacity */ -void nsCString::SetCapacity(PRUint32 aLength) { - if(aLength) { - if(aLength>mCapacity) { - GrowCapacity(*this,aLength); - } - AddNullTerminator(*this); +void +nsCString::SetCapacity( PRUint32 aNewCapacity ) + { + if ( aNewCapacity ) + { + if( aNewCapacity > mCapacity ) + GrowCapacity(*this,aNewCapacity); + AddNullTerminator(*this); + } + else + { + nsStr::Destroy(*this); + nsStr::Initialize(*this, eOneByte); + } } -} /********************************************************************** Accessor methods... @@ -742,7 +750,6 @@ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const { PRBool done=PR_FALSE; while((cpmCapacity) { - GrowCapacity(*this,aLength); - } - AddNullTerminator(*this); +void +nsString::SetCapacity( PRUint32 aNewCapacity ) + { + if ( aNewCapacity ) + { + if( aNewCapacity > mCapacity ) + GrowCapacity(*this, aNewCapacity); + AddNullTerminator(*this); + } + else + { + nsStr::Destroy(*this); + nsStr::Initialize(*this, eTwoByte); + } } -} /********************************************************************** Accessor methods... diff --git a/mozilla/xpcom/string/obsolete/nsString.cpp b/mozilla/xpcom/string/obsolete/nsString.cpp index 21e016f5016..c64c7b9340f 100644 --- a/mozilla/xpcom/string/obsolete/nsString.cpp +++ b/mozilla/xpcom/string/obsolete/nsString.cpp @@ -195,18 +195,26 @@ void nsCString::SetLength(PRUint32 anIndex) { /** - * Call this method if you want to force the string to a certain capacity - * @update gess 1/4/99 - * @param aLength -- contains new length for mStr + * Call this method if you want to force the string to a certain capacity; + * |SetCapacity(0)| discards associated storage. + * + * @param aNewCapacity -- desired minimum capacity */ -void nsCString::SetCapacity(PRUint32 aLength) { - if(aLength) { - if(aLength>mCapacity) { - GrowCapacity(*this,aLength); - } - AddNullTerminator(*this); +void +nsCString::SetCapacity( PRUint32 aNewCapacity ) + { + if ( aNewCapacity ) + { + if( aNewCapacity > mCapacity ) + GrowCapacity(*this,aNewCapacity); + AddNullTerminator(*this); + } + else + { + nsStr::Destroy(*this); + nsStr::Initialize(*this, eOneByte); + } } -} /********************************************************************** Accessor methods... @@ -742,7 +750,6 @@ PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const { PRBool done=PR_FALSE; while((cpmCapacity) { - GrowCapacity(*this,aLength); - } - AddNullTerminator(*this); +void +nsString::SetCapacity( PRUint32 aNewCapacity ) + { + if ( aNewCapacity ) + { + if( aNewCapacity > mCapacity ) + GrowCapacity(*this, aNewCapacity); + AddNullTerminator(*this); + } + else + { + nsStr::Destroy(*this); + nsStr::Initialize(*this, eTwoByte); + } } -} /********************************************************************** Accessor methods...