# HG changeset patch # User Mike Becker # Date 1651398850 -7200 # Node ID 7b9114030ca43c7bdcb602064d249261dd62865f # Parent 45bcfd152f85cba27e22dd6f7714905c0b37eb5d optimization for buffer write easy cases diff -r 45bcfd152f85 -r 7b9114030ca4 src/buffer.c --- 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;