From 19ae56b2b62c3fb591027f5cddf21795aa630a04 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 28 Nov 2011 10:36:13 +0100 Subject: CLEANUP: kill buffer_replace() and use an inline instead This function is never used, only its buffer_replace2() alternative is used. Replace the former with an inline which calls the later. --- include/proto/buffers.h | 14 +++++++++++- src/buffers.c | 56 ++++++---------------------------------------- 2 files changed, 21 insertions(+), 49 deletions(-) diff --git a/include/proto/buffers.h b/include/proto/buffers.h index 0d395a0..f0ea83d 100644 --- a/include/proto/buffers.h +++ b/include/proto/buffers.h @@ -45,7 +45,6 @@ int buffer_put_block(struct buffer *buf, const char *str, int len); int buffer_put_char(struct buffer *buf, char c); int buffer_get_line(struct buffer *buf, char *str, int len); int buffer_get_block(struct buffer *buf, char *blk, int len, int offset); -int buffer_replace(struct buffer *b, char *pos, char *end, const char *str); int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int len); int buffer_insert_line2(struct buffer *b, char *pos, const char *str, int len); void buffer_dump(FILE *o, struct buffer *b, int from, int to); @@ -575,6 +574,19 @@ static inline int buffer_feed(struct buffer *buf, const char *str) return -2; } + +/* This function writes the string at position which must be in + * buffer , and moves just after the end of . 's parameters + * (l, r, lr) are updated to be valid after the shift. the shift value + * (positive or negative) is returned. If there's no space left, the move is + * not done. The function does not adjust ->send_max nor BF_OUT_EMPTY because + * it does not make sense to use it on data scheduled to be sent. + */ +static inline int buffer_replace(struct buffer *b, char *pos, char *end, const char *str) +{ + return buffer_replace2(b, pos, end, str, strlen(str)); +} + /* * * Functions below are used to manage chunks diff --git a/src/buffers.c b/src/buffers.c index 43c0647..88d40ff 100644 --- a/src/buffers.c +++ b/src/buffers.c @@ -316,53 +316,14 @@ int buffer_get_block(struct buffer *buf, char *blk, int len, int offset) return len; } -/* - * this function writes the string at position which must be in buffer , - * and moves just after the end of . - * 's parameters (l, r, lr) are recomputed to be valid after the shift. - * the shift value (positive or negative) is returned. - * If there's no space left, the move is not done. - * The function does not adjust ->send_max nor BF_OUT_EMPTY because it does not - * make sense to use it on data scheduled to be sent. - * - */ -int buffer_replace(struct buffer *b, char *pos, char *end, const char *str) -{ - int delta; - int len; - - len = strlen(str); - delta = len - (end - pos); - - if (delta + b->r >= b->data + b->size) - return 0; /* no space left */ - - if (delta + b->r > b->w && b->w >= b->r && b->l) - return 0; /* no space left before wrapping data */ - - /* first, protect the end of the buffer */ - memmove(end + delta, end, b->r - end); - - /* now, copy str over pos */ - memcpy(pos, str,len); - - /* we only move data after the displaced zone */ - if (b->r > pos) b->r += delta; - if (b->lr > pos) b->lr += delta; - b->l += delta; - - b->flags &= ~BF_FULL; - if (b->l == 0) - b->r = b->w = b->lr = b->data; - if (b->l >= buffer_max_len(b)) - b->flags |= BF_FULL; - - return delta; -} - -/* - * same except that the string length is given, which allows str to be NULL if - * len is 0. The send limit is *not* adjusted. +/* This function writes the string at position which must be in + * buffer , and moves just after the end of . 's parameters + * (l, r, lr) are updated to be valid after the shift. the shift value + * (positive or negative) is returned. If there's no space left, the move is + * not done. The function does not adjust ->send_max nor BF_OUT_EMPTY because + * it does not make sense to use it on data scheduled to be sent. The string + * length is taken from parameter . If is null, the pointer + * is allowed to be null. */ int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int len) { @@ -397,7 +358,6 @@ int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int return delta; } - /* * Inserts followed by "\r\n" at position in buffer . The * argument informs about the length of string so that we don't have to -- 1.7.2.3