From 77ee44c7b6fc722e8f208599a775162c8308abc3 Mon Sep 17 00:00:00 2001 From: xaphier Date: Sat, 10 Oct 2015 12:14:51 +0200 Subject: [PATCH] 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. --- lib/zstd.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/zstd.c b/lib/zstd.c index a574efc9e..a150e6ea6 100644 --- a/lib/zstd.c +++ b/lib/zstd.c @@ -314,6 +314,7 @@ typedef struct ZSTD_Cctx_s #else U32 hashTable[HASH_TABLESIZE]; #endif + BYTE buffer[WORKPLACESIZE]; } cctxi_t; @@ -321,12 +322,7 @@ ZSTD_Cctx* ZSTD_createCCtx(void) { ZSTD_Cctx* ctx = (ZSTD_Cctx*) malloc( sizeof(ZSTD_Cctx) ); if (ctx==NULL) return NULL; - ctx->seqStore.buffer = malloc(WORKPLACESIZE); - if (ctx->seqStore.buffer==NULL) - { - free(ctx); - return NULL; - } + ctx->seqStore.buffer = ctx->buffer; ctx->seqStore.offsetStart = (U32*) (ctx->seqStore.buffer); ctx->seqStore.offCodeStart = (BYTE*) (ctx->seqStore.offsetStart + (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) { - free(ctx->seqStore.buffer); free(ctx); return 0; } -- 2.47.2