From: René Scharfe Date: Sun, 09 Feb 2020 10:23:26 GMT Subject: Re: [PATCH] strbuf: add and use strbuf_insertstr() Message-ID: In-Reply-To: <20200208230801.GA33529@syl.local> Am 09.02.20 um 00:08 schrieb Taylor Blau: > Hi René, > > On Sat, Feb 08, 2020 at 08:56:43PM +0100, René Scharfe wrote: >> Add a function for inserting a C string into a strbuf. Use it >> throughout the source to get rid of magic string length constants and >> explicit strlen() calls. >> >> Like strbuf_addstr(), implement it as an inline function to avoid the >> implicit strlen() calls to cause runtime overhead. > > This all looks quite reasonable to me. Did you have a specific > motivation in mind when writing this patch, other than to get rid of > having to call strlen on the same argument like: > > strbuf_insert(&buf, pos, x, strlen(x)) > > ? Not that this needs more motivation than that, I'm just curious. No, that's it. > I looked through 'git grep strbuf_insert(', and only noticed one spot > that I could be updated with 'strbuf_insertstr' in mailinfo.c: > > diff --git a/mailinfo.c b/mailinfo.c > index c535dec2e9..543962d40c 100644 > --- a/mailinfo.c > +++ b/mailinfo.c > @@ -570,7 +570,7 @@ static int check_header(struct mailinfo *mi, > len = strlen("Content-Type: "); > strbuf_add(&sb, line->buf + len, line->len - len); > decode_header(mi, &sb); > - strbuf_insert(&sb, 0, "Content-Type: ", len); > + strbuf_insertstr(&sb, 0, "Content-Type: "); > handle_content_type(mi, &sb); > ret = 1; > goto check_header_out; Right. Missed that one because the strlen() call is not in side the strbuf_insert() invocation. René