зеркало из https://github.com/mozilla/pjs.git
bug 112312 Removing 32k-1 allocs when reading jar files. Saves a bunch
of time (about 10% on win2k) on startup. r=cathleen,dveditz sr=darin
This commit is contained in:
Родитель
598da13ef3
Коммит
6e5c432bff
|
@ -1090,9 +1090,7 @@ PRInt32 nsZipArchive::CopyItemToDisk(const nsZipItem* aItem, PRFileDesc* fOut)
|
||||||
if ( SeekToItem( aItem ) != ZIP_OK )
|
if ( SeekToItem( aItem ) != ZIP_OK )
|
||||||
return ZIP_ERR_CORRUPT;
|
return ZIP_ERR_CORRUPT;
|
||||||
|
|
||||||
char* buf = (char*)PR_Malloc(ZIP_BUFLEN);
|
char buf[ZIP_BUFLEN];
|
||||||
if ( buf == 0 )
|
|
||||||
return ZIP_ERR_MEMORY;
|
|
||||||
|
|
||||||
//-- initialize crc
|
//-- initialize crc
|
||||||
crc = crc32(0L, Z_NULL, 0);
|
crc = crc32(0L, Z_NULL, 0);
|
||||||
|
@ -1125,7 +1123,6 @@ PRInt32 nsZipArchive::CopyItemToDisk(const nsZipItem* aItem, PRFileDesc* fOut)
|
||||||
if ( (status == ZIP_OK) && (crc != aItem->crc32) )
|
if ( (status == ZIP_OK) && (crc != aItem->crc32) )
|
||||||
status = ZIP_ERR_CORRUPT;
|
status = ZIP_ERR_CORRUPT;
|
||||||
|
|
||||||
PR_FREEIF( buf );
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1177,13 +1174,8 @@ PRInt32 nsZipArchive::InflateItem( const nsZipItem* aItem, PRFileDesc* fOut,
|
||||||
return ZIP_ERR_CORRUPT;
|
return ZIP_ERR_CORRUPT;
|
||||||
|
|
||||||
//-- allocate deflation buffers
|
//-- allocate deflation buffers
|
||||||
Bytef *inbuf = (Bytef*)PR_Malloc(ZIP_BUFLEN);
|
Bytef inbuf[ZIP_BUFLEN];
|
||||||
Bytef *outbuf = (Bytef*)PR_Malloc(ZIP_BUFLEN);
|
Bytef outbuf[ZIP_BUFLEN];
|
||||||
if ( inbuf == 0 || outbuf == 0 )
|
|
||||||
{
|
|
||||||
status = ZIP_ERR_MEMORY;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-- set up the inflate
|
//-- set up the inflate
|
||||||
memset( &zs, 0, sizeof(zs) );
|
memset( &zs, 0, sizeof(zs) );
|
||||||
|
@ -1312,8 +1304,6 @@ cleanup:
|
||||||
inflateEnd( &zs );
|
inflateEnd( &zs );
|
||||||
}
|
}
|
||||||
|
|
||||||
PR_FREEIF( inbuf );
|
|
||||||
PR_FREEIF( outbuf );
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1322,7 +1312,7 @@ cleanup:
|
||||||
//---------------------------------------------
|
//---------------------------------------------
|
||||||
PRInt32 nsZipArchive::TestItem( const nsZipItem* aItem )
|
PRInt32 nsZipArchive::TestItem( const nsZipItem* aItem )
|
||||||
{
|
{
|
||||||
Bytef *inbuf = NULL, *outbuf = NULL, *old_next_out;
|
Bytef inbuf[ZIP_BUFLEN], outbuf[ZIP_BUFLEN], *old_next_out;
|
||||||
PRUint32 size, chunk=0, inpos, crc;
|
PRUint32 size, chunk=0, inpos, crc;
|
||||||
PRInt32 status = ZIP_OK;
|
PRInt32 status = ZIP_OK;
|
||||||
int zerr = Z_OK;
|
int zerr = Z_OK;
|
||||||
|
@ -1341,17 +1331,6 @@ PRInt32 nsZipArchive::TestItem( const nsZipItem* aItem )
|
||||||
if ( SeekToItem( aItem ) != ZIP_OK )
|
if ( SeekToItem( aItem ) != ZIP_OK )
|
||||||
return ZIP_ERR_CORRUPT;
|
return ZIP_ERR_CORRUPT;
|
||||||
|
|
||||||
//-- allocate buffers
|
|
||||||
inbuf = (Bytef *) PR_Malloc(ZIP_BUFLEN);
|
|
||||||
if (aItem->compression == DEFLATED)
|
|
||||||
outbuf = (Bytef *) PR_Malloc(ZIP_BUFLEN);
|
|
||||||
|
|
||||||
if ( inbuf == 0 || (aItem->compression == DEFLATED && outbuf == 0) )
|
|
||||||
{
|
|
||||||
status = ZIP_ERR_MEMORY;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-- set up the inflate if DEFLATED
|
//-- set up the inflate if DEFLATED
|
||||||
if (aItem->compression == DEFLATED)
|
if (aItem->compression == DEFLATED)
|
||||||
{
|
{
|
||||||
|
@ -1481,10 +1460,6 @@ cleanup:
|
||||||
inflateEnd( &zs );
|
inflateEnd( &zs );
|
||||||
}
|
}
|
||||||
|
|
||||||
PR_FREEIF(inbuf);
|
|
||||||
if (aItem->compression == DEFLATED)
|
|
||||||
PR_FREEIF(outbuf);
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
#define ZIP_MAGIC 0x5A49505FL /* "ZIP_" */
|
#define ZIP_MAGIC 0x5A49505FL /* "ZIP_" */
|
||||||
#define ZIPFIND_MAGIC 0x5A495046L /* "ZIPF" */
|
#define ZIPFIND_MAGIC 0x5A495046L /* "ZIPF" */
|
||||||
#define ZIP_TABSIZE 256
|
#define ZIP_TABSIZE 256
|
||||||
#define ZIP_BUFLEN 32767
|
// Keep this odd. The -1 is significant.
|
||||||
|
#define ZIP_BUFLEN (4 * 1024 - 1)
|
||||||
|
|
||||||
#ifdef STANDALONE
|
#ifdef STANDALONE
|
||||||
#define nsZipArchive nsZipArchiveStandalone
|
#define nsZipArchive nsZipArchiveStandalone
|
||||||
|
|
Загрузка…
Ссылка в новой задаче