fix for #104929. some minor optimizations to nsStdURL.cpp.

use PL_strchr() instead of PL_strstr() when possible.

switch from PR_smprintf() to += and AppendInt(), to avoid the malloc and free.

r=sfraser, sr=darin
This commit is contained in:
sspitzer%netscape.com 2001-10-16 00:29:28 +00:00
parent 8acecc8399
commit 80a791c8d0

View File

@ -628,12 +628,8 @@ nsStdURL::GetSpec(char **o_Spec)
rv = AppendString(finalSpec,mHost,HOSTESCAPED,esc_Host);
if (-1 != mPort && mPort != mDefaultPort)
{
char* portBuffer = PR_smprintf(":%d", mPort);
if (!portBuffer)
return NS_ERROR_OUT_OF_MEMORY;
finalSpec += portBuffer;
PR_smprintf_free(portBuffer);
portBuffer = 0;
finalSpec += ':';
finalSpec.AppendInt(mPort);
}
}
char* ePath = nsnull;
@ -675,12 +671,8 @@ nsStdURL::GetPrePath(char **o_Spec)
rv = AppendString(finalSpec,mHost,HOSTESCAPED,esc_Host);
if (-1 != mPort && mDefaultPort != mPort)
{
char* portBuffer = PR_smprintf(":%d", mPort);
if (!portBuffer)
return NS_ERROR_OUT_OF_MEMORY;
finalSpec += portBuffer;
PR_smprintf_free(portBuffer);
portBuffer = 0;
finalSpec += ':';
finalSpec.AppendInt(mPort);
}
}
*o_Spec = ToNewCString(finalSpec);
@ -834,7 +826,7 @@ nsStdURL::Resolve(const char *relativePath, char **result)
rv = DupString(result, relativePath);
char* path = PL_strstr(*result,"://");
if (path) {
path = PL_strstr((char*)(path+3),"/");
path = PL_strchr((char*)(path+3),'/');
if (path)
CoaleseDirs(path);
}
@ -859,7 +851,7 @@ nsStdURL::Resolve(const char *relativePath, char **result)
if (*result) {
char* path = PL_strstr(*result,"://");
if (path) {
path = PL_strstr((char*)(path+3),"/");
path = PL_strchr((char*)(path+3),'/');
if (path)
CoaleseDirs(path);
}
@ -946,7 +938,7 @@ nsStdURL::Resolve(const char *relativePath, char **result)
if (*result) {
char* path = PL_strstr(*result,"://");
if (path) {
path = PL_strstr((char*)(path+3),"/");
path = PL_strchr((char*)(path+3),'/');
if (path)
CoaleseDirs(path);
}