From: Nick Bowler Date: Fri, 23 Jun 2023 03:37:54 +0000 (-0400) Subject: libcdecl: Simplify cdecl__advance. X-Git-Tag: v1.3~150 X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/commitdiff_plain/7df5e2a15f784ab786f56ca25d739c8b546ccde8?ds=sidebyside libcdecl: Simplify cdecl__advance. It seems unnecessary to set the dst pointer to null here, nothing cares if this pointer is null or not null, only the length matters. --- diff --git a/src/output.c b/src/output.c index 27921ab..cf5e2ff 100644 --- a/src/output.c +++ b/src/output.c @@ -24,15 +24,14 @@ #include "specstr.h" +#define MIN(a, b) ((a) < (b) ? (a) : (b)) + size_t cdecl__advance(struct output_state *dst, size_t amount) { - if (amount >= dst->dstlen) { - dst->dstlen = 0; - dst->dst = 0; - } else { - dst->dst += amount; - dst->dstlen -= amount; - } + size_t x = MIN(amount, dst->dstlen); + + dst->dst += x; + dst->dstlen -= x; return amount; }