]> git.ipfire.org Git - thirdparty/git.git/commit
strbuf: add strbuf_add_uint()
authorRené Scharfe <l.s.r@web.de>
Tue, 12 May 2026 11:56:00 +0000 (13:56 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 12 May 2026 15:48:42 +0000 (00:48 +0900)
commitcdeef283bcf8529fc858cfe7d18a7522294519c4
tree249397f5f24499ba3b25d11f2c88eb4ed3279025
parent94f057755b7941b321fd11fec1b2e3ca5313a4e0
strbuf: add strbuf_add_uint()

strbuf_addf() calls vsnprintf(3) underneath, which supports a plethora
of formatting options.  We can avoid its overhead in basic cases by
providing specialized functions like strbuf_addstr() for strings.  Add
another one, strbuf_add_uint(), for unsigned integers.

Prepare the number string in a temporary buffer.  Make it big enough for
any unsigned integer value: A decimal digit can represent ln(10)/ln(2) ≈
3.32 bits; dividing the number of bits of uintmax_t by 3.3 and rounding
up gives a sufficiently close conservative size estimate.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
strbuf.c
strbuf.h