Subject: Re: [PATCH 1/4] strbuf: add strbuf_add_uint()

From: Jeff King <[email-masked]>
Date: Thu, 14 May 2026 23:53:39 -0400

On Thu, May 14, 2026 at 01:09:24PM +0200, René Scharfe wrote:

> > And btw, one final thing to look at if you are interested in
> > micro-optimizing strbufs: using intrinsics for overflow detection.
> > 
> > Right now we use unsigned_add_overflows(), and then do the actual add.
> > Using __builtin_add_overflow() might be faster.
> Curious.  Clang and GCC emit the same instructions for our
> unsigned_add_overflows() vs. __builtin_add_overflow() on x64, but clang
> on ARM64 fails to elide the comparison: https://godbolt.org/z/91d35KofM

Ah, neat. I always assumed there was low-hanging fruit to pick here, but
it sounds like the compiler is (usually) more clever than I expected.

-Peff