]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Remove one malloc/free from compression 46/head
authorxaphier <el.3d.source@googlemail.com>
Sat, 10 Oct 2015 10:14:51 +0000 (12:14 +0200)
committerxaphier <el.3d.source@googlemail.com>
Sat, 10 Oct 2015 10:14:51 +0000 (12:14 +0200)
By making the buffer part of the zstd context structure, one malloc/free
can be removed from the compression.

lib/zstd.c

index a574efc9ecce64fbffa32920d2961cd0efae2d32..a150e6ea6a64488bbbfbfdb4f0a83f2610ebcf29 100644 (file)
@@ -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;
 }