diff --git a/xpcom/string/public/nsTSubstring.h b/xpcom/string/public/nsTSubstring.h index 14bba499d29d..fb8bc841a4cb 100644 --- a/xpcom/string/public/nsTSubstring.h +++ b/xpcom/string/public/nsTSubstring.h @@ -659,8 +659,25 @@ class nsTSubstring_CharT * this function returns false if is unable to allocate sufficient * memory. */ - PRBool NS_FASTCALL ReplacePrep( index_type cutStart, size_type cutLength, size_type newLength ); + PRBool ReplacePrep(index_type cutStart, size_type cutLength, + size_type newLength) + { + cutLength = NS_MIN(cutLength, mLength - cutStart); + PRUint32 newTotalLen = mLength - cutLength + newLength; + if (cutStart == mLength && Capacity() > newTotalLen) { + mFlags &= ~F_VOIDED; + mData[newTotalLen] = char_type(0); + mLength = newTotalLen; + return PR_TRUE; + } + return ReplacePrepInternal(cutStart, cutLength, newLength, newTotalLen); + } + PRBool NS_FASTCALL ReplacePrepInternal(index_type cutStart, + size_type cutLength, + size_type newFragLength, + size_type newTotalLength); + /** * returns the number of writable storage units starting at mData. * the value does not include space for the null-terminator character. diff --git a/xpcom/string/src/nsTSubstring.cpp b/xpcom/string/src/nsTSubstring.cpp index 2510c71c2d9d..1f31013e6c21 100644 --- a/xpcom/string/src/nsTSubstring.cpp +++ b/xpcom/string/src/nsTSubstring.cpp @@ -188,13 +188,9 @@ nsTSubstring_CharT::Finalize() } PRBool -nsTSubstring_CharT::ReplacePrep( index_type cutStart, size_type cutLen, size_type fragLen ) +nsTSubstring_CharT::ReplacePrepInternal(index_type cutStart, size_type cutLen, + size_type fragLen, size_type newLen) { - // bound cut length - cutLen = NS_MIN(cutLen, mLength - cutStart); - - PRUint32 newLen = mLength - cutLen + fragLen; - char_type* oldData; PRUint32 oldFlags; if (!MutatePrep(newLen, &oldData, &oldFlags))