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
Родитель 1adf5c8c45
Коммит e257d02ebd
2 изменённых файлов: 20 добавлений и 7 удалений

Просмотреть файл

@ -659,8 +659,25 @@ class nsTSubstring_CharT
* this function returns false if is unable to allocate sufficient * this function returns false if is unable to allocate sufficient
* memory. * 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. * returns the number of writable storage units starting at mData.
* the value does not include space for the null-terminator character. * the value does not include space for the null-terminator character.

Просмотреть файл

@ -188,13 +188,9 @@ nsTSubstring_CharT::Finalize()
} }
PRBool 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; char_type* oldData;
PRUint32 oldFlags; PRUint32 oldFlags;
if (!MutatePrep(newLen, &oldData, &oldFlags)) if (!MutatePrep(newLen, &oldData, &oldFlags))