From c43574d056718180737941b71234bc8fc35d3c58 Mon Sep 17 00:00:00 2001 From: bol-van Date: Wed, 7 Jan 2026 06:45:27 +0300 Subject: [PATCH] nfqws2: gzip optimize memory alloc --- nfq2/lua.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/nfq2/lua.c b/nfq2/lua.c index 387dedd..8705b8d 100644 --- a/nfq2/lua.c +++ b/nfq2/lua.c @@ -2668,6 +2668,8 @@ static int luacall_gunzip_end(lua_State *L) LUA_STACK_GUARD_RETURN(L,0) } #define BUFMIN 128 +#define Z_INFL_BUF_INCREMENT 16384 +#define Z_DEFL_BUF_INCREMENT 4096 static int luacall_gunzip_inflate(lua_State *L) { // gunzip_inflate(zstream, compressed_data, expected_uncompressed_chunk_size) return decompressed_data @@ -2689,8 +2691,16 @@ static int luacall_gunzip_inflate(lua_State *L) { if ((bufsize - size) < BUFMIN) { - bufsize += bufchunk; - newbuf = buf ? realloc(buf, bufsize) : malloc(bufsize); + if (buf) + { + bufsize += Z_INFL_BUF_INCREMENT; + newbuf = realloc(buf, bufsize); + } + else + { + bufsize += bufchunk; + newbuf = malloc(bufsize); + } if (!newbuf) { r = Z_MEM_ERROR; @@ -2793,8 +2803,16 @@ static int luacall_gzip_deflate(lua_State *L) { if ((bufsize - size) < BUFMIN) { - bufsize += bufchunk; - newbuf = buf ? realloc(buf, bufsize) : malloc(bufsize); + if (buf) + { + bufsize += Z_DEFL_BUF_INCREMENT; + newbuf = realloc(buf, bufsize); + } + else + { + bufsize += bufchunk; + newbuf = malloc(bufsize); + } if (!newbuf) { r = Z_MEM_ERROR;