bug 116191 Making nsZipItem a member of nsJarInputStream rather than a

pointer. Saves a 16 byte allocation on per jar file read. r=darin, sr=dveditz
This commit is contained in:
dp%netscape.com 2001-12-21 05:57:39 +00:00
Родитель def49c7eb7
Коммит 75409d6e33
4 изменённых файлов: 25 добавлений и 33 удалений

Просмотреть файл

@ -40,7 +40,7 @@ nsJARInputStream::Available(PRUint32 *_retval)
if (Zip() == nsnull)
*_retval = 0;
else
*_retval = Zip()->Available(mReadInfo);
*_retval = Zip()->Available(&mReadInfo);
return NS_OK;
}
@ -54,7 +54,7 @@ nsJARInputStream::Read(char* buf, PRUint32 count, PRUint32 *bytesRead)
return NS_OK;
}
PRInt32 err = Zip()->Read(mReadInfo, buf, count, bytesRead);
PRInt32 err = Zip()->Read(&mReadInfo, buf, count, bytesRead);
return err == ZIP_OK ? NS_OK : NS_ERROR_FAILURE;
}
@ -103,8 +103,6 @@ NS_IMETHODIMP
nsJARInputStream::Close()
{
NS_IF_RELEASE(mJAR);
if (mReadInfo)
delete mReadInfo;
return NS_OK;
}
@ -140,7 +138,7 @@ nsJARInputStream::Create(nsISupports* ignored, const nsIID& aIID, void* *aResult
//----------------------------------------------
nsJARInputStream::nsJARInputStream()
: mJAR(nsnull), mReadInfo(nsnull)
: mJAR(nsnull)
{
NS_INIT_REFCNT();
}

Просмотреть файл

@ -60,7 +60,7 @@ class nsJARInputStream : public nsIInputStream
protected:
nsJAR* mJAR;
nsZipRead* mReadInfo;
nsZipRead mReadInfo;
};
#endif /* nsJAR_h__ */

Просмотреть файл

@ -667,7 +667,7 @@ PRInt32 nsZipArchive::GetItem( const char * aFilename, nsZipItem **result)
//---------------------------------------------
// nsZipArchive::ReadInit
//---------------------------------------------
PRInt32 nsZipArchive::ReadInit(const char* zipEntry, nsZipRead** aRead)
PRInt32 nsZipArchive::ReadInit(const char* zipEntry, nsZipRead* aRead)
{
//-- Parameter validity check
if (zipEntry == 0 || aRead == 0)
@ -680,10 +680,8 @@ PRInt32 nsZipArchive::ReadInit(const char* zipEntry, nsZipRead** aRead)
if (!item)
return ZIP_ERR_FNF;
//-- Create nsZipRead object
*aRead = new nsZipRead(this, item);
if (aRead == 0)
return ZIP_ERR_MEMORY;
//-- Initialize nsZipRead object
aRead->Init(this, item);
//-- Read the item into memory
// Inflate if necessary and save in mInflatedFileBuffer
@ -704,7 +702,7 @@ PRInt32 nsZipArchive::ReadInit(const char* zipEntry, nsZipRead** aRead)
}
if (result == ZIP_OK)
(*aRead)->mFileBuffer = buf;
aRead->mFileBuffer = buf;
return result;
}
@ -1735,27 +1733,11 @@ nsZipItem::~nsZipItem()
}
//------------------------------------------
// nsZipRead constructor and destructor
// nsZipRead
//------------------------------------------
MOZ_DECL_CTOR_COUNTER(nsZipRead)
nsZipRead::nsZipRead( nsZipArchive* aZipArchive, nsZipItem* aZipItem )
: mArchive(aZipArchive),
mItem(aZipItem),
mCurPos(0),
mFileBuffer(0)
{
MOZ_COUNT_CTOR(nsZipRead);
}
nsZipRead::~nsZipRead()
{
PR_FREEIF(mFileBuffer);
MOZ_COUNT_DTOR(nsZipRead);
}
//------------------------------------------
// nsZipFind constructor and destructor
//------------------------------------------

Просмотреть файл

@ -163,10 +163,10 @@ public:
* before any calls to Read or Available
*
* @param zipEntry name of item in file
* @param (out) a structure used by Read and Available
* @param aRead is filled with appropriate values
* @return status code
*/
PRInt32 ReadInit(const char* zipEntry, nsZipRead** aRead);
PRInt32 ReadInit(const char* zipEntry, nsZipRead* aRead);
/**
* Read
@ -269,8 +269,20 @@ class nsZipRead
{
public:
nsZipRead( nsZipArchive* aZip, nsZipItem* item );
~nsZipRead();
nsZipRead() { MOZ_COUNT_CTOR(nsZipRead); }
~nsZipRead()
{
PR_FREEIF(mFileBuffer);
MOZ_COUNT_DTOR(nsZipRead);
}
void Init( nsZipArchive* aZip, nsZipItem* aZipItem )
{
mArchive = aZip;
mItem = aZipItem;
mCurPos = 0;
mFileBuffer = NULL;
}
nsZipArchive* mArchive;
nsZipItem* mItem;