Bug #22960 --> help improve message display performance. This routine would get called for each

line of data parsed by mime for displaying a message. It was making 4 copies of the line inside of it. I
used some nsString magic to reduce the number of allocations to just one! *yeah*
r=rhp
a=phil
This commit is contained in:
mscott%netscape.com 2000-03-02 06:14:33 +00:00
parent c8143e7e8c
commit 8085e187d1
2 changed files with 22 additions and 22 deletions

View File

@ -296,25 +296,23 @@ MimeInlineTextPlainFlowed_parse_line (char *line, PRInt32 length, MimeObject *ob
PRUnichar* wresult = nsnull;
nsresult rv = NS_OK;
// we should modify scantxt to take a char * instead of a unicode string so we can
// reduce the number of string copying going on.
rv = conv->ScanTXT(strline.GetUnicode(),obj->options->whattodo, &wresult);
if (NS_FAILED(rv))
return -1;
//XXX I18N Converting PRUnichar* to char*
nsAutoString strresult(wresult);
char* cresult = strresult.ToNewCString();
Recycle(wresult);
if (!cresult)
return -1;
// avoid an extra string copy by using nsSubsumeStr, this transfers ownership of
// wresult to strresult so don't try to free wresult later.
nsString strresult(nsSubsumeStr(wresult, PR_TRUE /* assume ownership */, nsCRT::strlen(wresult)));
PRInt32 copyLen = strresult.Length();
if (copyLen > (obj->obuffer_size - 10))
copyLen = obj->obuffer_size - 10;
nsCRT::memcpy(templine, cresult, copyLen);
obj->obuffer[copyLen] = '\0';
Recycle(cresult);
// avoid yet another extra string copy of the line by using .ToCString which will
// convert and copy directly into the buffer we have already allocated.
strresult.ToCString(templine, buffersizeneeded - 10);
}
else
{

View File

@ -138,6 +138,11 @@ MimeInlineTextPlain_parse_eof (MimeObject *obj, PRBool abort_p)
static int
MimeInlineTextPlain_parse_line (char *line, PRInt32 length, MimeObject *obj)
{
// this routine gets called for every line of data that comes through the mime
// converter. It's important to make sure we are efficient with
// how we allocate memory in this routine. be careful if you go to add
// more to this routine.
int status;
NS_ASSERTION(length > 0, "zero length");
@ -180,24 +185,21 @@ MimeInlineTextPlain_parse_line (char *line, PRInt32 length, MimeObject *obj)
nsresult rv = NS_OK;
PRUnichar* wresult = nsnull;
// we should force scanTXT to take a char * instead of a unicode string
// so we don't have to make an extra copy of the line just to convert it to unicode
rv = conv->ScanTXT(strline.GetUnicode(), obj->options->whattodo, &wresult);
if (NS_FAILED(rv))
return -1;
//XXX I18N Converting PRUnichar* to char*
nsAutoString strresult(wresult);
char* cresult = strresult.ToNewCString();
Recycle(wresult);
if (!cresult)
return -1;
// avoid an extra string copy by using nsSubsumeStr, this transfers ownership of
// wresult to strresult so don't try to free wresult later.
nsString strresult(nsSubsumeStr(wresult, PR_TRUE /* assume ownership */, nsCRT::strlen(wresult)));
PRInt32 copyLen = strresult.Length();
if (copyLen > (obj->obuffer_size - 10))
copyLen = obj->obuffer_size - 10;
nsCRT::memcpy(obj->obuffer, cresult, copyLen);
obj->obuffer[copyLen] = '\0';
Recycle(cresult);
// avoid yet another extra string copy of the line by using .ToCString which will
// convert and copy directly into the buffer we have already allocated.
strresult.ToCString(obj->obuffer, obj->obuffer_size - 10);
}
else
{