From fc51b4a0b2f4f3e0546054b8262afded30e1f1c1 Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Thu, 27 Dec 2018 21:16:52 +0100 Subject: cbuf: remove range checking function There isn't a single case where the range check cannot be replaced with an index check, which is slightly lighter. --- src/cbuf.c | 4 ++-- src/cbuf.h | 8 -------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/cbuf.c b/src/cbuf.c index 2baad37..a176b2a 100644 --- a/src/cbuf.c +++ b/src/cbuf.c @@ -143,13 +143,13 @@ cbuf_write(struct cbuf *cbuf, size_t index, const void *buf, size_t size) uint8_t *start, *end, *buf_end; size_t new_end, skip; - if (!cbuf_range_valid(cbuf, index, cbuf->end)) { + if (!cbuf_index_valid(cbuf, index)) { return EINVAL; } new_end = index + size; - if (!cbuf_range_valid(cbuf, cbuf->start, new_end)) { + if (!cbuf_index_valid(cbuf, new_end)) { cbuf->end = new_end; if (size > cbuf_capacity(cbuf)) { diff --git a/src/cbuf.h b/src/cbuf.h index 354cc34..6b6a844 100644 --- a/src/cbuf.h +++ b/src/cbuf.h @@ -89,14 +89,6 @@ cbuf_index_valid(const struct cbuf *cbuf, size_t index) && ((cbuf->end - index) <= cbuf_size(cbuf)); } -static inline bool -cbuf_range_valid(const struct cbuf *cbuf, size_t start, size_t end) -{ - return (((end - start) <= cbuf_size(cbuf)) - && ((start - cbuf->start) <= cbuf_size(cbuf)) - && ((cbuf->end - end) <= cbuf_size(cbuf))); -} - /* * Initialize a circular buffer. * -- cgit v1.2.3