From: Quim Rovira Date: Sun, 14 Aug 2016 09:08:20 +0000 (+0200) Subject: Use a local temporary buffer for decompression instead of a global. X-Git-Tag: 0.002~29 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=261eae0ae1af69612e6952c0dc35f1aed7670192;p=io-compress-brotli.git Use a local temporary buffer for decompression instead of a global. Allocating the temporary buffer on each call to decompress might be slightly less efficient, but that would mostly impact streaming decompression with very small blocks. Not even sure this change is really worth doing.. it could use some benchmarking to see if it really makes sense. --- diff --git a/Brotli.xs b/Brotli.xs index 9eb25e2..4378e97 100644 --- a/Brotli.xs +++ b/Brotli.xs @@ -9,7 +9,6 @@ #include #define BUFFER_SIZE 1048576 -static uint8_t buffer[BUFFER_SIZE]; /* It's almost 2016, is anyone still using ithreads? */ MODULE = IO::Compress::Brotli PACKAGE = IO::Uncompress::Brotli PROTOTYPES: ENABLE @@ -50,11 +49,12 @@ SV* BrotliDecoderDecompressStream(state, in) SV* state SV* in PREINIT: - uint8_t *next_in, *next_out; + uint8_t *next_in, *next_out, *buffer; size_t available_in, available_out; BrotliDecoderResult result; CODE: next_in = (uint8_t*) SvPV(in, available_in); + Newx(buffer, BUFFER_SIZE, uint8_t); RETVAL = newSVpv("", 0); result = BROTLI_RESULT_NEEDS_MORE_OUTPUT; while(result == BROTLI_RESULT_NEEDS_MORE_OUTPUT) { @@ -67,10 +67,12 @@ SV* BrotliDecoderDecompressStream(state, in) &next_out, NULL ); if(!result){ - croak("Error in BrotliDecoderDecompressStream"); + Safefree(buffer); + croak("Error in BrotliDecoderDecompressStream"); } sv_catpvn(RETVAL, (const char*)buffer, BUFFER_SIZE-available_out); } + Safefree(buffer); OUTPUT: RETVAL