From: Marko Kreen Date: Wed, 1 Aug 2007 19:43:42 +0000 (+0000) Subject: use memchr() in mbuf_get_string X-Git-Tag: pgbouncer_1_1~76 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d8ece1e2fda8c3670d1babdb16d4836b4b59ca04;p=pgbouncer use memchr() in mbuf_get_string --- diff --git a/src/mbuf.h b/src/mbuf.h index 9bb38bd..687a9ef 100644 --- a/src/mbuf.h +++ b/src/mbuf.h @@ -81,17 +81,6 @@ static inline const uint8 * mbuf_get_bytes(MBuf *buf, unsigned len) return res; } -static inline const char * mbuf_get_string(MBuf *buf) -{ - const char *res = (const char *)buf->pos; - while (buf->pos < buf->end && *buf->pos) - buf->pos++; - if (buf->pos == buf->end) - return NULL; - buf->pos++; - return res; -} - static inline unsigned mbuf_avail(MBuf *buf) { return buf->end - buf->pos; @@ -102,3 +91,13 @@ static inline unsigned mbuf_size(MBuf *buf) return buf->end - buf->data; } +static inline const char * mbuf_get_string(MBuf *buf) +{ + const char *res = (const char *)buf->pos; + const uint8 *nul = memchr(res, 0, mbuf_avail(buf)); + if (!nul) + return NULL; + buf->pos = nul + 1; + return res; +} +