From f7d044737685eb26935e1b173a49cc8661e7cdc1 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 20 Jul 2018 16:20:34 +0200 Subject: [PATCH] MINOR: buffers: split b_putblk() into __b_putblk() 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 | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/include/common/buf.h b/include/common/buf.h index 4ccc8b0ed6..b93ef9946d 100644 --- a/include/common/buf.h +++ b/include/common/buf.h @@ -486,29 +486,31 @@ static inline void b_putchr(struct buffer *b, char c) b->data++; } +/* __b_putblk() : tries to append bytes from block to the end of + * buffer 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 at the end of buffer . 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; } -- 2.39.5