From: Ondřej Surý Date: Fri, 16 Dec 2022 10:43:20 +0000 (+0100) Subject: Add isc_buffer_trycompact() function needed for StreamDNS X-Git-Tag: v9.19.9~69^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=460afcda183c6348e03ea6f8830821cadf0d3665;p=thirdparty%2Fbind9.git Add isc_buffer_trycompact() function needed for StreamDNS Add isc_buffer_trycompact() that's an optimization; it will compact the buffer only when the remaining length is smaller than used length. --- diff --git a/lib/isc/include/isc/buffer.h b/lib/isc/include/isc/buffer.h index 2877d211791..16df98dc28a 100644 --- a/lib/isc/include/isc/buffer.h +++ b/lib/isc/include/isc/buffer.h @@ -265,6 +265,8 @@ isc_buffer_reinit(isc_buffer_t *b, void *base, unsigned int length); * */ +static inline void +isc_buffer_trycompact(isc_buffer_t *b); static inline void isc_buffer_compact(isc_buffer_t *b); /*!< @@ -1043,6 +1045,13 @@ isc_buffer_reinit(isc_buffer_t *b, void *base, unsigned int length) { b->length = length; } +static inline void +isc_buffer_trycompact(isc_buffer_t *b) { + if (isc_buffer_consumedlength(b) >= isc_buffer_remaininglength(b)) { + isc_buffer_compact(b); + } +} + static inline void isc_buffer_compact(isc_buffer_t *b) { unsigned int length;