]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Partially inline flush_pending inlining 1952/head
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Mon, 18 Aug 2025 13:20:05 +0000 (15:20 +0200)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Fri, 22 Aug 2025 09:26:17 +0000 (11:26 +0200)
arch/s390/dfltcc_deflate.c
deflate.c
deflate_p.h

index 90b4b96e9ce33509e717eebd71749dc5b4b9128c..03ef2f0ebc4aee80458f741b99769abad774b11d 100644 (file)
@@ -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
index 8b198ec1592c12c2d7f37c080ebc254f434d3554..9372c21f0c320e2e7467029ce6c36fd95a785bb5 100644 (file)
--- 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.
      */
index 2619af9a80c85a136d30b6d06b09661fce8332c0..c7ef730489b6f61aa1e013866814ad4435eae19a 100644 (file)
@@ -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