]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add isc_buffer_trycompact() function needed for StreamDNS
authorOndřej Surý <ondrej@isc.org>
Fri, 16 Dec 2022 10:43:20 +0000 (11:43 +0100)
committerOndřej Surý <ondrej@isc.org>
Tue, 20 Dec 2022 18:13:48 +0000 (19:13 +0100)
Add isc_buffer_trycompact() that's an optimization; it will compact the
buffer only when the remaining length is smaller than used length.

lib/isc/include/isc/buffer.h

index 2877d211791d76cad3530cc58cda925ed5300d02..16df98dc28aec2a880fbb2ebf3778d2d8f7afea3 100644 (file)
@@ -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;