MINOR: buffer: merge b{i,o}_contig_space()
These ones were merged into a single b_contig_space() that covers both
(the bo_ case was a simplified version of the other one). The function
doesn't use ->i nor ->o anymore.
diff --git a/include/common/buf.h b/include/common/buf.h
index 0ee9c54..33830f7 100644
--- a/include/common/buf.h
+++ b/include/common/buf.h
@@ -293,6 +293,24 @@
return data;
}
+/* b_contig_space() : returns the amount of bytes that can be appended to the
+ * buffer at once.
+ */
+static inline size_t b_contig_space(const struct buffer *b)
+{
+ const char *left, *right;
+
+ right = b_head(b);
+ left = right + b_data(b);
+
+ if (left >= b_wrap(b))
+ left -= b_size(b);
+ else
+ right = b_wrap(b);
+
+ return right - left;
+}
+
/*********************************************/
/* Functions used to modify the buffer state */
diff --git a/include/common/buffer.h b/include/common/buffer.h
index 8638bd6..10ff640 100644
--- a/include/common/buffer.h
+++ b/include/common/buffer.h
@@ -105,46 +105,6 @@
b->o -= del;
}
-/* Return the amount of bytes that can be written into the input area at once
- * including reserved space which may be overwritten (this is the caller
- * responsibility to know if the reserved space is protected or not).
-*/
-static inline int bi_contig_space(const struct buffer *b)
-{
- const char *left, *right;
-
- left = b->p + b->i;
- right = b->p - b->o;
- if (left >= b->data + b->size)
- left -= b->size;
- else {
- if (right < b->data)
- right += b->size;
- else
- right = b->data + b->size;
- }
- return (right - left);
-}
-
-/* Return the amount of bytes that can be written into the output area at once
- * including reserved space which may be overwritten (this is the caller
- * responsibility to know if the reserved space is protected or not). Input data
- * are assumed to not exist.
-*/
-static inline int bo_contig_space(const struct buffer *b)
-{
- const char *left, *right;
-
- left = b->p;
- right = b->p - b->o;
- if (right < b->data)
- right += b->size;
- else
- right = b->data + b->size;
-
- return (right - left);
-}
-
/* Return the buffer's length in bytes by summing the input and the output */
static inline int buffer_len(const struct buffer *buf)
{
@@ -334,7 +294,7 @@
if (!len)
return 0;
- half = bo_contig_space(b);
+ half = b_contig_space(b);
if (half > len)
half = len;
@@ -444,7 +404,7 @@
if (!len)
return 0;
- half = bi_contig_space(b);
+ half = b_contig_space(b);
if (half > len)
half = len;
diff --git a/src/channel.c b/src/channel.c
index 62a860b..fc1bf12 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -92,7 +92,7 @@
}
c_realign_if_empty(chn);
- max = bo_contig_space(chn->buf);
+ max = b_contig_space(chn->buf);
if (len > max)
return max;
@@ -166,7 +166,7 @@
return 0;
/* OK so the data fits in the buffer in one or two blocks */
- max = bi_contig_space(chn->buf);
+ max = b_contig_space(chn->buf);
memcpy(ci_tail(chn), blk, MIN(len, max));
if (len > max)
memcpy(chn->buf->data, blk + max, len - max);
diff --git a/src/mux_h2.c b/src/mux_h2.c
index e2f96c7..0284279 100644
--- a/src/mux_h2.c
+++ b/src/mux_h2.c
@@ -2989,7 +2989,7 @@
while (1) {
outbuf.str = b_tail(h2c->mbuf);
- outbuf.size = bo_contig_space(h2c->mbuf);
+ outbuf.size = b_contig_space(h2c->mbuf);
outbuf.len = 0;
if (outbuf.size >= 9 || !b_space_wraps(h2c->mbuf))
@@ -3147,7 +3147,7 @@
while (1) {
outbuf.str = b_tail(h2c->mbuf);
- outbuf.size = bo_contig_space(h2c->mbuf);
+ outbuf.size = b_contig_space(h2c->mbuf);
outbuf.len = 0;
if (outbuf.size >= 9 || !b_space_wraps(h2c->mbuf))