Backing out my checkin for bug 206682 due to performance regression (slowing down NS_ConvertUCS2toUTF8).

git-svn-id: svn://10.0.0.236/trunk@142777 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dbaron%dbaron.org
2003-05-23 00:32:54 +00:00
parent 5305218645
commit bce712ae10
8 changed files with 266 additions and 398 deletions

View File

@@ -209,18 +209,24 @@ NS_COM
char*
ToNewUTF8String( const nsAString& aSource )
{
nsAString::const_iterator start, end;
CalculateUTF8Size calculator;
copy_string(aSource.BeginReading(start), aSource.EndReading(end),
calculator);
// XXX The conversion code in NS_ConvertUCS2toUTF8 needs to be
// refactored so that we can use it here without a double-copy.
NS_ConvertUCS2toUTF8 temp(aSource);
char *result = NS_STATIC_CAST(char*,
nsMemory::Alloc(calculator.Size() + 1));
char* result;
if (temp.GetOwnsBuffer()) {
// We allocated. Trick the string into not freeing its buffer to
// avoid an extra allocation.
result = temp.mStr;
ConvertUCS2toUTF8 converter(result);
copy_string(aSource.BeginReading(start), aSource.EndReading(end),
converter).write_terminator();
NS_ASSERTION(calculator.Size() == converter.Size(), "length mismatch");
temp.mStr=0;
temp.SetOwnsBuffer(PR_FALSE);
}
else {
// We didn't allocate a buffer, so we need to copy it out of the
// nsCAutoString's storage.
result = ToNewCString(temp);
}
return result;
}