mirror of
https://github.com/facebook/zstd.git
synced 2025-10-10 00:03:36 -04:00
Remove one malloc/free from compression
By making the buffer part of the zstd context structure, one malloc/free can be removed from the compression.
This commit is contained in:
parent
be50aaa0ee
commit
77ee44c7b6
@ -314,6 +314,7 @@ typedef struct ZSTD_Cctx_s
|
|||||||
#else
|
#else
|
||||||
U32 hashTable[HASH_TABLESIZE];
|
U32 hashTable[HASH_TABLESIZE];
|
||||||
#endif
|
#endif
|
||||||
|
BYTE buffer[WORKPLACESIZE];
|
||||||
} cctxi_t;
|
} cctxi_t;
|
||||||
|
|
||||||
|
|
||||||
@ -321,12 +322,7 @@ ZSTD_Cctx* ZSTD_createCCtx(void)
|
|||||||
{
|
{
|
||||||
ZSTD_Cctx* ctx = (ZSTD_Cctx*) malloc( sizeof(ZSTD_Cctx) );
|
ZSTD_Cctx* ctx = (ZSTD_Cctx*) malloc( sizeof(ZSTD_Cctx) );
|
||||||
if (ctx==NULL) return NULL;
|
if (ctx==NULL) return NULL;
|
||||||
ctx->seqStore.buffer = malloc(WORKPLACESIZE);
|
ctx->seqStore.buffer = ctx->buffer;
|
||||||
if (ctx->seqStore.buffer==NULL)
|
|
||||||
{
|
|
||||||
free(ctx);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
ctx->seqStore.offsetStart = (U32*) (ctx->seqStore.buffer);
|
ctx->seqStore.offsetStart = (U32*) (ctx->seqStore.buffer);
|
||||||
ctx->seqStore.offCodeStart = (BYTE*) (ctx->seqStore.offsetStart + (BLOCKSIZE>>2));
|
ctx->seqStore.offCodeStart = (BYTE*) (ctx->seqStore.offsetStart + (BLOCKSIZE>>2));
|
||||||
ctx->seqStore.litStart = ctx->seqStore.offCodeStart + (BLOCKSIZE>>2);
|
ctx->seqStore.litStart = ctx->seqStore.offCodeStart + (BLOCKSIZE>>2);
|
||||||
@ -344,7 +340,6 @@ void ZSTD_resetCCtx(ZSTD_Cctx* ctx)
|
|||||||
|
|
||||||
size_t ZSTD_freeCCtx(ZSTD_Cctx* ctx)
|
size_t ZSTD_freeCCtx(ZSTD_Cctx* ctx)
|
||||||
{
|
{
|
||||||
free(ctx->seqStore.buffer);
|
|
||||||
free(ctx);
|
free(ctx);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user