Bug 810151: readahead for ordered jar files r=taras

--HG--
extra : rebase_source : dd7984ff2dd7a57e77b8c5c74ab82ad5d033a772
This commit is contained in:
Aaron Klotz 2013-03-06 11:58:29 -07:00
parent 10eff2ffe5
commit 1a9e9e36e7
2 changed files with 29 additions and 1 deletions

View File

@ -30,6 +30,7 @@
#define ZIP_ARENABLOCKSIZE (1*1024)
#ifdef XP_UNIX
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <limits.h>
@ -156,6 +157,9 @@ nsresult gZlibInit(z_stream *zs)
nsZipHandle::nsZipHandle()
: mFileData(nullptr)
, mLen(0)
#if defined(XP_WIN)
, mFd(nullptr)
#endif
, mMap(nullptr)
, mRefCnt(0)
{
@ -168,7 +172,11 @@ NS_IMPL_THREADSAFE_RELEASE(nsZipHandle)
nsresult nsZipHandle::Init(nsIFile *file, nsZipHandle **ret)
{
mozilla::AutoFDClose fd;
nsresult rv = file->OpenNSPRFileDesc(PR_RDONLY, 0000, &fd.rwget());
int32_t flags = PR_RDONLY;
#if defined(XP_WIN)
flags |= nsIFile::OS_READAHEAD;
#endif
nsresult rv = file->OpenNSPRFileDesc(flags, 0000, &fd.rwget());
if (NS_FAILED(rv))
return rv;
@ -194,6 +202,9 @@ nsresult nsZipHandle::Init(nsIFile *file, nsZipHandle **ret)
return NS_ERROR_OUT_OF_MEMORY;
}
#if defined(XP_WIN)
handle->mFd = fd.forget();
#endif
handle->mMap = map;
handle->mFile.Init(file);
handle->mLen = (uint32_t) size;
@ -231,6 +242,11 @@ int64_t nsZipHandle::SizeOfMapping()
nsZipHandle::~nsZipHandle()
{
#if defined(XP_WIN)
if (mFd) {
PR_Close(mFd);
}
#endif
if (mMap) {
PR_MemUnmap((void *)mFileData, mLen);
PR_CloseFileMap(mMap);
@ -569,6 +585,15 @@ MOZ_WIN_MEM_TRY_BEGIN
uint32_t centralOffset = 4;
if (mFd->mLen > ZIPCENTRAL_SIZE && xtolong(startp + centralOffset) == CENTRALSIG) {
// Success means optimized jar layout from bug 559961 is in effect
uint32_t readaheadLength = xtolong(startp);
if (readaheadLength) {
#if defined(XP_UNIX)
madvise(const_cast<uint8_t*>(startp), readaheadLength, MADV_WILLNEED);
#elif defined(XP_WIN)
HANDLE hFile = (HANDLE) PR_FileDesc2NativeHandle(mFd->mFd);
mozilla::ReadAhead(hFile, 0, readaheadLength);
#endif
}
} else {
for (buf = endp - ZIPEND_SIZE; buf > startp; buf--)
{

View File

@ -392,6 +392,9 @@ private:
nsZipHandle();
~nsZipHandle();
#if defined(XP_WIN)
PRFileDesc * mFd; /* nspr file descriptor */
#endif
PRFileMap * mMap; /* nspr datastructure for mmap */
nsAutoPtr<nsZipItemPtr<uint8_t> > mBuf;
nsrefcnt mRefCnt; /* ref count */