Get rid of unnecessary loop counter

Incrementing counters in those loops are redundant
as we are keeping track of the ptr offsets anyways
This commit is contained in:
Felix Kopp 2020-11-11 19:53:08 +01:00
parent 1fa5d159a7
commit 2778fad339
No known key found for this signature in database
GPG key ID: C478BA0A85F75728

View file

@ -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)