From ca12d4e7848c8f3ae5cbfbad3993fe7a56fc68a5 Mon Sep 17 00:00:00 2001 From: "rjc%netscape.com" Date: Thu, 30 Dec 1999 23:37:35 +0000 Subject: [PATCH] Bulk read datasets in one read operation... slight speed improvement. --- suite/browser/src/nsInternetSearchService.cpp | 34 +++++++++++-------- .../search/src/nsInternetSearchService.cpp | 34 +++++++++++-------- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/suite/browser/src/nsInternetSearchService.cpp b/suite/browser/src/nsInternetSearchService.cpp index 2301f4be0a5..6c243d3b2a9 100755 --- a/suite/browser/src/nsInternetSearchService.cpp +++ b/suite/browser/src/nsInternetSearchService.cpp @@ -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); } diff --git a/xpfe/components/search/src/nsInternetSearchService.cpp b/xpfe/components/search/src/nsInternetSearchService.cpp index 2301f4be0a5..6c243d3b2a9 100755 --- a/xpfe/components/search/src/nsInternetSearchService.cpp +++ b/xpfe/components/search/src/nsInternetSearchService.cpp @@ -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); }