]> 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>
Sat, 23 Aug 2025 17:18:21 +0000 (19:18 +0200)
arch/s390/dfltcc_deflate.c
deflate.c
deflate_p.h

index 8216771f3d72b83cb4cefff4ff3e14dd1041f10e..f602b44be46190da409ac975ee649950ccf703df 100644 (file)
@@ -92,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, 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 37de31439d24c129b5c64fe950849efa9ee51bcf..e803300e9ab47e5dde50188b5dcfa8e4805b78e7 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;
+}
+
 /* ===========================================================================
  * Reverse the first len bits of a code using bit manipulation
  */