From 79fe5b3f5587acd7f0a7af6400ca19eac95c5a53 Mon Sep 17 00:00:00 2001 From: Hans Kristian Rosbach Date: Mon, 18 Aug 2025 15:20:05 +0200 Subject: [PATCH] Partially inline flush_pending --- arch/s390/dfltcc_deflate.c | 3 ++- deflate.c | 29 +++++------------------------ deflate_p.h | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/arch/s390/dfltcc_deflate.c b/arch/s390/dfltcc_deflate.c index 90b4b96e..03ef2f0e 100644 --- a/arch/s390/dfltcc_deflate.c +++ b/arch/s390/dfltcc_deflate.c @@ -15,6 +15,7 @@ #include "zbuild.h" #include "deflate.h" +#include "deflate_p.h" #include "trees_emit.h" #include "dfltcc_deflate.h" #include "dfltcc_detail.h" @@ -91,7 +92,7 @@ static inline void send_eobs(PREFIX3(streamp) strm, const struct dfltcc_param_v0 deflate_state *state = (deflate_state *)strm->state; send_bits(state, PREFIX(bi_reverse)(param->eobs >> (15 - param->eobl), param->eobl), param->eobl, state->bi_buf, state->bi_valid); - PREFIX(flush_pending)(strm); + flush_pending_inline(strm); if (state->pending != 0) { /* The remaining data is located in pending_out[0:pending]. If someone * calls put_byte() - this might happen in deflate() - the byte will be diff --git a/deflate.c b/deflate.c index 8b198ec1..9372c21f 100644 --- a/deflate.c +++ b/deflate.c @@ -741,29 +741,10 @@ unsigned long Z_EXPORT PREFIX(deflateBound)(PREFIX3(stream) *strm, unsigned long } /* ========================================================================= - * Flush as much pending output as possible. All deflate() output, except for - * some deflate_stored() output, goes through this function so some - * applications may wish to modify it to avoid allocating a large - * strm->next_out buffer and copying into it. (See also read_buf()). + * Flush as much pending output as possible. See flush_pending_inline() */ Z_INTERNAL void PREFIX(flush_pending)(PREFIX3(stream) *strm) { - uint32_t len; - deflate_state *s = strm->state; - - zng_tr_flush_bits(s); - len = MIN(s->pending, strm->avail_out); - if (len == 0) - return; - - Tracev((stderr, "[FLUSH]")); - memcpy(strm->next_out, s->pending_out, len); - strm->next_out += len; - s->pending_out += len; - strm->total_out += len; - strm->avail_out -= len; - s->pending -= len; - if (s->pending == 0) - s->pending_out = s->pending_buf; + flush_pending_inline(strm); } /* =========================================================================== @@ -797,7 +778,7 @@ int32_t Z_EXPORT PREFIX(deflate)(PREFIX3(stream) *strm, int32_t flush) { /* Flush as much pending output as possible */ if (s->pending != 0) { - PREFIX(flush_pending)(strm); + flush_pending_inline(strm); if (strm->avail_out == 0) { /* Since avail_out is 0, deflate will be called again with * more output space, but possibly with both pending and @@ -983,7 +964,7 @@ int32_t Z_EXPORT PREFIX(deflate)(PREFIX3(stream) *strm, int32_t flush) { s->status = BUSY_STATE; /* Compression must start with an empty pending buffer */ - PREFIX(flush_pending)(strm); + flush_pending_inline(strm); if (s->pending != 0) { s->last_flush = -1; return Z_OK; @@ -1059,7 +1040,7 @@ int32_t Z_EXPORT PREFIX(deflate)(PREFIX3(stream) *strm, int32_t flush) { if (s->wrap == 1) put_uint32_msb(s, strm->adler); } - PREFIX(flush_pending)(strm); + flush_pending_inline(strm); /* If avail_out is zero, the application will call deflate again * to flush the rest. */ diff --git a/deflate_p.h b/deflate_p.h index 2619af9a..c7ef7304 100644 --- a/deflate_p.h +++ b/deflate_p.h @@ -98,6 +98,32 @@ static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t le return (s->sym_next == s->sym_end); } +/* ========================================================================= + * Flush as much pending output as possible. All deflate() output, except for some + * deflate_stored() output, goes through this function so some applications may wish to + * modify it to avoid allocating a large strm->next_out buffer and copying into it. + * See also read_buf(). + */ +Z_FORCEINLINE static void flush_pending_inline(PREFIX3(stream) *strm) { + uint32_t len; + deflate_state *s = strm->state; + + zng_tr_flush_bits(s); + len = MIN(s->pending, strm->avail_out); + if (len == 0) + return; + + Tracev((stderr, "[FLUSH]")); + memcpy(strm->next_out, s->pending_out, len); + strm->next_out += len; + s->pending_out += len; + strm->total_out += len; + strm->avail_out -= len; + s->pending -= len; + if (s->pending == 0) + s->pending_out = s->pending_buf; +} + /* =========================================================================== * Read a new buffer from the current input stream, update the adler32 and total number of * bytes read. All deflate() input goes through this function so some applications may wish -- 2.47.2