]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffers: split b_putblk() into __b_putblk()
authorWilly Tarreau <w@1wt.eu>
Fri, 20 Jul 2018 14:20:34 +0000 (16:20 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 20 Jul 2018 17:21:43 +0000 (19:21 +0200)
The latter function is more suited to operations that don't require any
check because the check has already been performed. It will be used by
other b_* functions.

include/common/buf.h

index 4ccc8b0ed63d1f5dcb073bb1f6b82cf2d7b74675..b93ef9946d5b56a964b7fb79221aec1c3003dbea 100644 (file)
@@ -486,29 +486,31 @@ static inline void b_putchr(struct buffer *b, char c)
        b->data++;
 }
 
+/* __b_putblk() : tries to append <len> bytes from block <blk> to the end of
+ * buffer <b> without checking for free space (it's up to the caller to do it).
+ * Supports wrapping. It must not be called with len == 0.
+ */
+static inline void __b_putblk(struct buffer *b, const char *blk, size_t len)
+{
+       size_t half = b_contig_space(b);
+
+       memcpy(b_tail(b), blk, half);
+
+       if (len > half)
+               memcpy(b_peek(b, b_data(b) + half), blk + half, len - half);
+       b->data += len;
+}
+
 /* b_putblk() : tries to append block <blk> at the end of buffer <b>. Supports
  * wrapping. Data are truncated if buffer is too short. It returns the number
  * of bytes copied.
  */
 static inline size_t b_putblk(struct buffer *b, const char *blk, size_t len)
 {
-       size_t half;
-
        if (len > b_room(b))
                len = b_room(b);
-       if (!len)
-               return 0;
-
-       half = b_contig_space(b);
-       if (half > len)
-               half = len;
-
-       memcpy(b_tail(b), blk, half);
-       b->data += half;
-       if (len > half) {
-               memcpy(b_tail(b), blk + half, len - half);
-               b->data += len - half;
-       }
+       if (len)
+               __b_putblk(b, blk, len);
        return len;
 }