Re: [PATCH/RFC 1/1] diff.c: When appropriate, use utf8_strwidth()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 14, 2022, 23:12 UTC
- Message-ID
- <xmqqfshy773n.fsf@gitster.g>
- In-Reply-To
- <20220814133531.16952-1-tboegi@web.de>
tboegi@web.de writes:
Show 9 quoted lines
> The choosen solution is to split code in diff.c like this > > strbuf_addf(&out, "%-*s", len, name); > > into 2 calls, like this: > > strbuf_addf(&out, "%s", name); > if (len > utf8_strwidth(name)) > strbuf_addchars(&out, ' ', len - utf8_strwidth(name));
Makes sense. Is utf8_strwidth(name) cheap enough that we can call it twice in a row on the same string casually, or should we avoid it with a new variable?
It might be worth doing a helper function, even?
static inline strbuf_pad(struct strbuf *out, const char *s, size_t width)
{
size_t w = utf8_strwidth(s);strbuf_addstr(out, s); if (w < width) strbuf_addchars(out, ' ', width - w); }
Other than that, sounds very sensible.