Bug 600301 - Optimize ReplacePrep, r=benjamin, a=benjamin

--HG--
extra : rebase_source : 92cff8659239f2e62a9588234f9d3ef00f255c85
This commit is contained in:
Olli Pettay 2010-11-07 21:39:04 +02:00
parent 1adf5c8c45
commit e257d02ebd
2 changed files with 20 additions and 7 deletions

View File

@ -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.

View File

@ -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))