Sun, 01 May 2022 11:54:10 +0200
optimization for buffer write easy cases
src/buffer.c | file | annotate | diff | comparison | revisions |
--- a/src/buffer.c Sun May 01 11:46:54 2022 +0200 +++ b/src/buffer.c Sun May 01 11:54:10 2022 +0200 @@ -140,7 +140,16 @@ size_t nitems, CxBuffer *buffer ) { - // TODO: optimize for special case size == nitems == 1 + // optimize for easy case + if (size == 1 && (buffer->capacity - buffer->pos) >= nitems) { + memcpy(buffer->bytes + buffer->pos, ptr, nitems); + buffer->pos += nitems; + if (buffer->pos > buffer->size) { + buffer->size = buffer->pos; + } + return nitems; + } + size_t len; if (cx_szmul(size, nitems, &len)) { return 0;