From 2778fad339de8cfc0256b8b36dff77a6472c30ea Mon Sep 17 00:00:00 2001 From: Felix Kopp Date: Wed, 11 Nov 2020 19:53:08 +0100 Subject: [PATCH] Get rid of unnecessary loop counter Incrementing counters in those loops are redundant as we are keeping track of the ptr offsets anyways --- kernel/ringbuf.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/kernel/ringbuf.c b/kernel/ringbuf.c index 034b885..80bedb3 100644 --- a/kernel/ringbuf.c +++ b/kernel/ringbuf.c @@ -28,34 +28,32 @@ inline void ringbuf_destroy(struct ringbuf *buf) size_t ringbuf_read(uint8_t *dest, struct ringbuf *buf, size_t len) { - size_t n = 0; + uint8_t *tmp = dest; while (len-- > 0 && buf->rpos != buf->wpos) { - *dest++ = buf->data[buf->rpos++]; - n++; + *tmp++ = buf->data[buf->rpos++]; /* wrap around */ if (buf->rpos = buf->size) buf->rpos = 0; } - return n; + return tmp - dest; } size_t ringbuf_write(struct ringbuf *buf, const uint8_t *src, size_t len) { - size_t n = 0; + uint8_t *tmp = src; while (len-- > 0 && buf->wpos != buf->rpos) { - buf->data[buf->wpos++] = *src++; - n++; + buf->data[buf->wpos++] = *tmp++; /* wrap around */ if (buf->wpos = buf->size) buf->wpos = 0; } - return n; + return tmp - src; } size_t ringbuf_size(struct ringbuf *buf)