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:
parent
1fa5d159a7
commit
2778fad339
1 changed files with 6 additions and 8 deletions
|
@ -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 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) {
|
while (len-- > 0 && buf->rpos != buf->wpos) {
|
||||||
*dest++ = buf->data[buf->rpos++];
|
*tmp++ = buf->data[buf->rpos++];
|
||||||
n++;
|
|
||||||
|
|
||||||
/* wrap around */
|
/* wrap around */
|
||||||
if (buf->rpos = buf->size)
|
if (buf->rpos = buf->size)
|
||||||
buf->rpos = 0;
|
buf->rpos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return tmp - dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ringbuf_write(struct ringbuf *buf, const uint8_t *src, size_t len)
|
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) {
|
while (len-- > 0 && buf->wpos != buf->rpos) {
|
||||||
buf->data[buf->wpos++] = *src++;
|
buf->data[buf->wpos++] = *tmp++;
|
||||||
n++;
|
|
||||||
|
|
||||||
/* wrap around */
|
/* wrap around */
|
||||||
if (buf->wpos = buf->size)
|
if (buf->wpos = buf->size)
|
||||||
buf->wpos = 0;
|
buf->wpos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return tmp - src;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ringbuf_size(struct ringbuf *buf)
|
size_t ringbuf_size(struct ringbuf *buf)
|
||||||
|
|
Loading…
Reference in a new issue