Bug 1219310 - part 1 - ask the prefs file for its size directly; r=njn

Calling nsIInputStream::Available on nsIFileInputStreams is relatively
expensive, as it requires three system calls: one to determine the
current file position, one to seek to the end file position, and one to
rewind to the previous file position.

We can do better by asking the file for its size directly, prior to
opening the stream.  This only requires one system call, stat, and is
thus superior--at least in considering the number of system calls.
This commit is contained in:
Nathan Froyd 2015-10-28 12:16:33 -04:00
parent 9c8cb321ef
commit 8ecc1d6489

View File

@ -1000,8 +1000,8 @@ static nsresult openPrefFile(nsIFile* aFile)
if (NS_FAILED(rv))
return rv;
uint64_t fileSize64;
rv = inStr->Available(&fileSize64);
int64_t fileSize64;
rv = aFile->GetFileSize(&fileSize64);
if (NS_FAILED(rv))
return rv;
NS_ENSURE_TRUE(fileSize64 <= UINT32_MAX, NS_ERROR_FILE_TOO_BIG);