Bulk read datasets in one read operation... slight speed improvement.

This commit is contained in:
rjc%netscape.com 1999-12-30 23:37:35 +00:00
parent 6e30a612df
commit 68abfa817c
2 changed files with 40 additions and 28 deletions

View File

@ -2021,26 +2021,32 @@ InternetSearchDataSource::GetSearchEngineList(nsFileSpec nativeDir, PRBool check
nsresult
InternetSearchDataSource::ReadFileContents(nsFileSpec baseFilename, nsString& sourceContents)
InternetSearchDataSource::ReadFileContents(nsFileSpec fileSpec, nsString& sourceContents)
{
nsresult rv = NS_OK;
nsInputFileStream searchFile(baseFilename);
nsresult rv = NS_ERROR_FAILURE;
PRUint32 contentsLen;
char *contents;
if (searchFile.is_open())
sourceContents.Truncate();
contentsLen = fileSpec.GetFileSize();
if (contentsLen > 0)
{
nsRandomAccessInputStream stream(searchFile);
char buffer[1024];
while (!stream.eof())
contents = new char [contentsLen + 1];
if (contents)
{
stream.readline(buffer, sizeof(buffer)-1 );
sourceContents += buffer;
sourceContents += "\n";
nsInputFileStream inputStream(fileSpec); // defaults to read only
PRInt32 howMany = inputStream.read(contents, contentsLen);
if (PRUint32(howMany) == contentsLen)
{
contents[contentsLen] = '\0';
sourceContents = contents;
rv = NS_OK;
}
delete [] contents;
contents = nsnull;
}
}
else
{
rv = NS_ERROR_FAILURE;
}
return(rv);
}

View File

@ -2021,26 +2021,32 @@ InternetSearchDataSource::GetSearchEngineList(nsFileSpec nativeDir, PRBool check
nsresult
InternetSearchDataSource::ReadFileContents(nsFileSpec baseFilename, nsString& sourceContents)
InternetSearchDataSource::ReadFileContents(nsFileSpec fileSpec, nsString& sourceContents)
{
nsresult rv = NS_OK;
nsInputFileStream searchFile(baseFilename);
nsresult rv = NS_ERROR_FAILURE;
PRUint32 contentsLen;
char *contents;
if (searchFile.is_open())
sourceContents.Truncate();
contentsLen = fileSpec.GetFileSize();
if (contentsLen > 0)
{
nsRandomAccessInputStream stream(searchFile);
char buffer[1024];
while (!stream.eof())
contents = new char [contentsLen + 1];
if (contents)
{
stream.readline(buffer, sizeof(buffer)-1 );
sourceContents += buffer;
sourceContents += "\n";
nsInputFileStream inputStream(fileSpec); // defaults to read only
PRInt32 howMany = inputStream.read(contents, contentsLen);
if (PRUint32(howMany) == contentsLen)
{
contents[contentsLen] = '\0';
sourceContents = contents;
rv = NS_OK;
}
delete [] contents;
contents = nsnull;
}
}
else
{
rv = NS_ERROR_FAILURE;
}
return(rv);
}