diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2021-03-16 01:05:47 -0400 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2021-03-26 07:33:42 -0400 |
commit | 38c873585020ac35f04cd2a7a2a56c8ecd7b0064 (patch) | |
tree | 277cd740fec455850e618cb30f3a40f4e402f5f1 /src/buffer.h | |
parent | f9cd50b782e860b54feee2b0ae8f0279058e85fe (diff) | |
download | lighttpd-git-38c873585020ac35f04cd2a7a2a56c8ecd7b0064.tar.gz |
[multiple] optimize primitives, buffer_extend()
optimize buffer_* primitives
Other than buffer_string_set_length(), reallocate with one power-2 step
in size (or use the requested size, if larger). This replaces the fixed
BUFFER_PIECE_SIZE round-up of only 64 bytes extension each reallocation,
which could lead to excessive reallocations in some scenarios.
buffer_extend() convenience routine to prep for batch append
(combines buffer_string_prepare_append() and buffer_commit())
mod_fastcgi, mod_scgi, mod_proxy and others now leverage buffer_extend()
mod_scgi directly performs little-endian encoding of short ints
http_response_write_header() optimizes writing response header,
leveraging buffer_extend()
modify mod_proxy to append line ends
similar to how it is done in http_response_write_header()
(removes one call to buffer_append_string_len())
Diffstat (limited to 'src/buffer.h')
-rw-r--r-- | src/buffer.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/buffer.h b/src/buffer.h index d055c085..2a5bb4dc 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -62,6 +62,13 @@ char* buffer_string_prepare_copy(buffer *b, size_t size); __attribute_returns_nonnull__ char* buffer_string_prepare_append(buffer *b, size_t size); +/* extend and modify buffer for immediate addition of x bytes (differs from + * buffer_string_prepare_append() which only ensures space is available) + * returns pointer to which callers should immediately write x bytes + */ +__attribute_returns_nonnull__ +char* buffer_extend(buffer * const restrict b, size_t x); + /* use after prepare_(copy,append) when you have written data to the buffer * to increase the buffer length by size. also sets the terminating zero. * requires enough space is present for the terminating zero (prepare with the @@ -99,11 +106,11 @@ __attribute_cold__ void buffer_free_ptr(buffer *b); void buffer_copy_string(buffer * restrict b, const char * restrict s); -void buffer_copy_string_len(buffer * restrict b, const char * restrict s, size_t s_len); +void buffer_copy_string_len(buffer * restrict b, const char * restrict s, size_t len); static inline void buffer_copy_buffer(buffer * restrict b, const buffer * restrict src); void buffer_append_string(buffer * restrict b, const char * restrict s); -void buffer_append_string_len(buffer * restrict b, const char * restrict s, size_t s_len); +void buffer_append_string_len(buffer * restrict b, const char * restrict s, size_t len); static inline void buffer_append_string_buffer(buffer * restrict b, const buffer * restrict src); #define buffer_append_uint_hex(b,len) buffer_append_uint_hex_lc((b),(len)) |