Don't use memcpy for single-character Replace/Assign since it performs worse than simple assignment. Bug 312681, r+sr=darin.

This commit is contained in:
bryner%brianryner.com 2005-10-17 16:28:21 +00:00
parent 7016d8085d
commit ddd7501923
2 changed files with 22 additions and 2 deletions

View File

@ -300,7 +300,7 @@ class nsTSubstring_CharT : public nsTAString_CharT
* assignment
*/
void Assign( char_type c ) { Assign(&c, 1); }
NS_COM void NS_FASTCALL Assign( char_type c );
NS_COM void NS_FASTCALL Assign( const char_type* data, size_type length = size_type(-1) );
NS_COM void NS_FASTCALL Assign( const self_type& );
NS_COM void NS_FASTCALL Assign( const substring_tuple_type& );
@ -341,7 +341,7 @@ class nsTSubstring_CharT : public nsTAString_CharT
* buffer manipulation
*/
void Replace( index_type cutStart, size_type cutLength, char_type c ) { Replace(cutStart, cutLength, &c, 1); }
NS_COM void NS_FASTCALL Replace( index_type cutStart, size_type cutLength, char_type c );
NS_COM void NS_FASTCALL Replace( index_type cutStart, size_type cutLength, const char_type* data, size_type length = size_type(-1) );
void Replace( index_type cutStart, size_type cutLength, const self_type& str ) { Replace(cutStart, cutLength, str.Data(), str.Length()); }
NS_COM void NS_FASTCALL Replace( index_type cutStart, size_type cutLength, const substring_tuple_type& tuple );

View File

@ -283,6 +283,15 @@ nsTSubstring_CharT::EnsureMutable()
// ---------------------------------------------------------------------------
// This version of Assign is optimized for single-character assignment.
void
nsTSubstring_CharT::Assign( char_type c )
{
if (ReplacePrep(0, mLength, 1))
*mData = c;
}
void
nsTSubstring_CharT::Assign( const char_type* data, size_type length )
{
@ -421,6 +430,17 @@ nsTSubstring_CharT::Adopt( char_type* data, size_type length )
}
// This version of Replace is optimized for single-character replacement.
void
nsTSubstring_CharT::Replace( index_type cutStart, size_type cutLength, char_type c )
{
cutStart = PR_MIN(cutStart, Length());
if (ReplacePrep(cutStart, cutLength, 1))
mData[cutStart] = c;
}
void
nsTSubstring_CharT::Replace( index_type cutStart, size_type cutLength, const char_type* data, size_type length )
{