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++];
buf->len--;
/* wrap around */
if (buf->rpos == buf->capacity)
buf->rpos = 0;
/* wrap around if required */
buf->rpos %= buf->capacity;
}
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->len++;
/* wrap around */
if (buf->wpos == buf->capacity)
buf->wpos = 0;
/* wrap around if required */
buf->wpos %= buf->capacity;
}
return (size_t)tmp - (size_t)src;