Get rid of unnecessary if branch

Branching is slow compared to ALU operations and stuff, you know
This commit is contained in:
Felix Kopp 2020-11-28 04:20:39 +01:00
parent fe87a65ded
commit 2ce25193fd
No known key found for this signature in database
GPG key ID: C478BA0A85F75728

View file

@ -35,9 +35,8 @@ size_t ringbuf_read(void *dest, struct ringbuf *buf, size_t len)
*tmp++ = buf->data[buf->rpos++]; *tmp++ = buf->data[buf->rpos++];
buf->len--; buf->len--;
/* wrap around */ /* wrap around if required */
if (buf->rpos == buf->capacity) buf->rpos %= buf->capacity;
buf->rpos = 0;
} }
return (size_t)tmp - (size_t)dest; return (size_t)tmp - (size_t)dest;
@ -51,9 +50,8 @@ size_t ringbuf_write(struct ringbuf *buf, const void *src, size_t len)
buf->data[buf->wpos++] = *tmp++; buf->data[buf->wpos++] = *tmp++;
buf->len++; buf->len++;
/* wrap around */ /* wrap around if required */
if (buf->wpos == buf->capacity) buf->wpos %= buf->capacity;
buf->wpos = 0;
} }
return (size_t)tmp - (size_t)src; return (size_t)tmp - (size_t)src;