]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: istbuf: add b_fromist() to make a buffer from an ist
authorWilly Tarreau <w@1wt.eu>
Thu, 17 Oct 2019 08:38:10 +0000 (10:38 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 17 Oct 2019 08:40:47 +0000 (10:40 +0200)
A lot of our chunk-based functions are able to work on a buffer pointer
but not on an ist. Instead of duplicating all of them to also take an
ist as a source, let's have a macro to make a temporary dummy buffer
from an ist. This will only result in structure field manipulations
that the compiler will quickly figure to eliminate them with inline
functions, and in other cases it will just use 4 words in the stack
before calling a function, instead of performing intermediary
conversions.

include/common/istbuf.h

index 9b6ce7c6bdf4ea9918225fedf56473297c78d843..933ec99fb4ccc7cd384f0f306fa4728f1d0fa32f 100644 (file)
@@ -33,6 +33,9 @@
 #include <common/ist.h>
 
 
+/* makes a buffer pointer from an IST */
+#define b_fromist(in) ({ const struct ist __i = (in); &(const struct buffer){ .area = __i.ptr, .head = 0, .data = __i.len, .size = __i.len}; })
+
 /* b_isteq() : returns > 0 if the first <n> characters of buffer <b> starting
  * at offset <o> relative to the buffer's head match <ist>. (empty strings do
  * match). It is designed to be used with reasonably small strings (it matches