Re: [PATCH] strbuf: add and use strbuf_insertstr()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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é




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux