]> git.draconx.ca Git - cdecl99.git/commitdiff
libcdecl: Simplify cdecl__advance.
authorNick Bowler <nbowler@draconx.ca>
Fri, 23 Jun 2023 03:37:54 +0000 (23:37 -0400)
committerNick Bowler <nbowler@draconx.ca>
Fri, 23 Jun 2023 05:03:44 +0000 (01:03 -0400)
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.

src/output.c

index 27921abb70b9bd6339cfc510af25dec46d826a5b..cf5e2ffa7ef076f062e78e04f1ce0a0f13057f32 100644 (file)
 
 #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;
 }