MINOR: http: replace http_message_realign() with buffer_slow_realign()
There is no more reason for the realign function being HTTP specific,
it only operates on a buffer now. Let's move it to buffers.c instead.
It's likely that buffer_bounce_realign is broken (not used), this will
have to be inspected. The function is worth rewriting as it can be
cheaper than buffer_slow_realign() to realign large wrapping buffers.
diff --git a/src/buffers.c b/src/buffers.c
index e71f852..7becb48 100644
--- a/src/buffers.c
+++ b/src/buffers.c
@@ -388,6 +388,34 @@
}
+/* This function realigns input data in a possibly wrapping buffer so that it
+ * becomes contiguous and starts at the beginning of the buffer area. The
+ * function may only be used when the buffer's output is empty.
+ */
+void buffer_slow_realign(struct buffer *buf)
+{
+ /* two possible cases :
+ * - the buffer is in one contiguous block, we move it in-place
+ * - the buffer is in two blocks, we move it via the swap_buffer
+ */
+ if (buf->i) {
+ int block1 = buf->i;
+ int block2 = 0;
+ if (buf->p + buf->i > buf->data + buf->size) {
+ /* non-contiguous block */
+ block1 = buf->data + buf->size - buf->p;
+ block2 = buf->p + buf->i - (buf->data + buf->size);
+ }
+ if (block2)
+ memcpy(swap_buffer, buf->data, block2);
+ memmove(buf->data, buf->p, block1);
+ if (block2)
+ memcpy(buf->data + block1, swap_buffer, block2);
+ }
+
+ buf->p = buf->data;
+}
+
/* Realigns a possibly non-contiguous buffer by bouncing bytes from source to
* destination. It does not use any intermediate buffer and does the move in
* place, though it will be slower than a simple memmove() on contiguous data,