From 0aac38f5b25f25b2472f991e3275dc976a9aa47e Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 22 Dec 2013 00:27:58 +0100 Subject: rb: improve the performance of rb_put when we call rb_put with a size greater than the size of the ring buffer itself, we used to copy in a loop, overriding our new written datas. it was very inefficient so we avoid these computations closes #1 --- src/rb.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/rb.c b/src/rb.c index ce269fb..a04d0cf 100644 --- a/src/rb.c +++ b/src/rb.c @@ -38,6 +38,23 @@ t_rb *rb_put(t_rb *rb, const void *src, size_t n) { size_t size; + size = rb_get_size(rb); + if (n >= size) { + /* we will override the whole ring buffer */ + + /* the first bytes of src will not be copied, anyway */ + src += (n - size); + + memcpy(rb->buffer, src , size); + + /* hardcode the values */ + rb->size_filled = size; + rb->off_w = 0; + rb->off_r = 0; + + return rb; + } + /* loop until n bytes of src have been written */ while (n != 0) { size = MIN(n, rb_get_size(rb) - rb->off_w); -- cgit v1.2.3