]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: kill buffer_replace() and use an inline instead
authorWilly Tarreau <w@1wt.eu>
Mon, 28 Nov 2011 09:36:13 +0000 (10:36 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 28 Nov 2011 20:01:28 +0000 (21:01 +0100)
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
src/buffers.c

index 0d395a077346079fc34c272d1844ac302f86087e..f0ea83d5334065af9faf16bd9a81bf2c75e275c5 100644 (file)
@@ -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 <str> at position <pos> which must be in
+ * buffer <b>, and moves <end> just after the end of <str>. <b>'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
index 43c06473bbf6f364ff3203626df13bfecebb2319..88d40ff184d3f0d0377a0786b918f99b0f565833 100644 (file)
@@ -316,53 +316,14 @@ int buffer_get_block(struct buffer *buf, char *blk, int len, int offset)
        return len;
 }
 
-/*
- * this function writes the string <str> at position <pos> which must be in buffer <b>,
- * and moves <end> just after the end of <str>.
- * <b>'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 <str> at position <pos> which must be in
+ * buffer <b>, and moves <end> just after the end of <str>. <b>'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 <len>. If <len> is null, the <str> 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 <str> followed by "\r\n" at position <pos> in buffer <b>. The <len>
  * argument informs about the length of string <str> so that we don't have to