From d8ece1e2fda8c3670d1babdb16d4836b4b59ca04 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Wed, 1 Aug 2007 19:43:42 +0000 Subject: [PATCH] use memchr() in mbuf_get_string --- src/mbuf.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) 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; +} + -- 2.50.1