Merge pull request #2956 from jtojanen/gzip

Set GZIP internal buffer size to 256k (default 8k)
pull/2961/head
Jens Steube 3 years ago committed by GitHub
commit acb4f80874
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,8 +21,8 @@
_Static_assert(sizeof (size_t) == sizeof (SizeT), "Check why sizeof(size_t) != sizeof(SizeT)");
#endif
#ifndef XZFILE_BUFFER_SIZE
#define XZFILE_BUFFER_SIZE 1024 * 1024
#ifndef HCFILE_BUFFER_SIZE
#define HCFILE_BUFFER_SIZE 256 * 1024
#endif
static bool xz_initialized = false;
@ -149,6 +149,8 @@ bool hc_fopen (HCFILE *fp, const char *path, const char *mode)
if (is_gzip)
{
if ((fp->gfp = gzdopen (fp->fd, mode)) == NULL) return false;
gzbuffer (fp->gfp, HCFILE_BUFFER_SIZE);
}
else if (is_zip)
{
@ -175,7 +177,7 @@ bool hc_fopen (HCFILE *fp, const char *path, const char *mode)
xfp->alloc.numAlignBits = 7;
xfp->alloc.baseAlloc = &xz_alloc;
ISzAllocPtr alloc = &xfp->alloc.vt;
xfp->inBuf = (Byte *) ISzAlloc_Alloc (alloc, XZFILE_BUFFER_SIZE);
xfp->inBuf = (Byte *) ISzAlloc_Alloc (alloc, HCFILE_BUFFER_SIZE);
if (xfp->inBuf == NULL)
{
hcfree (xfp);
@ -201,7 +203,7 @@ bool hc_fopen (HCFILE *fp, const char *path, const char *mode)
CLookToRead2 lookStream;
LookToRead2_CreateVTable (&lookStream, false);
lookStream.buf = xfp->inBuf;
lookStream.bufSize = XZFILE_BUFFER_SIZE;
lookStream.bufSize = HCFILE_BUFFER_SIZE;
lookStream.realStream = &inStream->vt;
LookToRead2_Init (&lookStream);
Xzs_Construct (&xfp->streams);
@ -221,7 +223,7 @@ bool hc_fopen (HCFILE *fp, const char *path, const char *mode)
xfp->outSize = Xzs_GetUnpackSize (&xfp->streams);
/* seek to start of the file and fill the buffer */
SizeT inLen = XZFILE_BUFFER_SIZE;
SizeT inLen = HCFILE_BUFFER_SIZE;
res = ISeekInStream_Seek (&inStream->vt, &offset, SZ_SEEK_SET);
if (res == SZ_OK)
{
@ -424,7 +426,7 @@ size_t hc_fread (void *ptr, size_t size, size_t nmemb, HCFILE *fp)
if (xfp->inLen == xfp->inPos && !xfp->inEof)
{
xfp->inPos = 0;
xfp->inLen = XZFILE_BUFFER_SIZE;
xfp->inLen = HCFILE_BUFFER_SIZE;
res = ISeekInStream_Read (&xfp->inStream.vt, xfp->inBuf, &xfp->inLen);
if (res != SZ_OK || xfp->inLen == 0) xfp->inEof = true;
}
@ -585,7 +587,7 @@ void hc_rewind (HCFILE *fp)
XzUnpacker_Init (&xfp->state);
/* fill the buffer */
SizeT inLen = XZFILE_BUFFER_SIZE;
SizeT inLen = HCFILE_BUFFER_SIZE;
res = ISeekInStream_Read (&inStream->vt, xfp->inBuf, &inLen);
if (res != SZ_OK || inLen == 0) return;
@ -706,7 +708,7 @@ int hc_fgetc (HCFILE *fp)
if (xfp->inLen == xfp->inPos && !xfp->inEof)
{
xfp->inPos = 0;
xfp->inLen = XZFILE_BUFFER_SIZE;
xfp->inLen = HCFILE_BUFFER_SIZE;
res = ISeekInStream_Read (&xfp->inStream.vt, xfp->inBuf, &xfp->inLen);
if (res != SZ_OK || xfp->inLen == 0) xfp->inEof = true;
}
@ -758,7 +760,7 @@ char *hc_fgets (char *buf, int len, HCFILE *fp)
if (xfp->inLen == xfp->inPos && !xfp->inEof)
{
xfp->inPos = 0;
xfp->inLen = XZFILE_BUFFER_SIZE;
xfp->inLen = HCFILE_BUFFER_SIZE;
res = ISeekInStream_Read (&xfp->inStream.vt, xfp->inBuf, &xfp->inLen);
if (res != SZ_OK || xfp->inLen == 0) xfp->inEof = true;
}

Loading…
Cancel
Save