git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Mike Hommey <mh@glandium.org>, Jeff King <peff@peff.net>
Cc: Elijah Newren <newren@gmail.com>, git@vger.kernel.org, gitster@pobox.com
Subject: Re: [PATCH 2/2] fast-import: duplicate into history rather than passing ownership
Date: Sun, 25 Aug 2019 16:21:54 +0200	[thread overview]
Message-ID: <248c5f9f-ba44-6dec-6f30-f7d193bc22bb@web.de> (raw)
In-Reply-To: <20190825100213.fssjydohathfhhe5@glandium.org>

Am 25.08.19 um 12:02 schrieb Mike Hommey:
> On Sun, Aug 25, 2019 at 04:10:55AM -0400, Jeff King wrote:
>> diff --git a/fast-import.c b/fast-import.c
>> index ee7258037a..1f9160b645 100644
>> --- a/fast-import.c
>> +++ b/fast-import.c
>> @@ -1763,7 +1763,6 @@ static int read_next_command(void)
>>  		} else {
>>  			struct recent_command *rc;
>>
>> -			strbuf_detach(&command_buf, NULL);
>>  			stdin_eof = strbuf_getline_lf(&command_buf, stdin);
>>  			if (stdin_eof)
>>  				return EOF;
>> @@ -1784,7 +1783,7 @@ static int read_next_command(void)
>>  				free(rc->buf);
>>  			}
>>
>> -			rc->buf = command_buf.buf;
>> +			rc->buf = xstrdup(command_buf.buf);
>
> You could xstrndup(command_buf.buf, command_buf.len), which would avoid
> a hidden strlen.

xstrndup() also searches for NUL, albeit with memchr(3).  xmemdupz()
would copy without checking.

I suspect the simplicity of xstrdup() outweighs the benefits of the
alternatives, but didn't do any measurements..

René

  reply	other threads:[~2019-08-25 14:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-25  4:13 [PATCH] fast-import: Reinitialize command_buf rather than detach it Mike Hommey
2019-08-25  6:57 ` Jeff King
2019-08-25  7:20   ` Mike Hommey
2019-08-25  7:28     ` Jeff King
2019-08-25  8:06   ` [PATCH 0/2] fast-import input string handling bugs Jeff King
2019-08-25  8:08     ` [PATCH 1/2] fast-import: duplicate parsed encoding string Jeff King
2019-08-26 18:28       ` Elijah Newren
2019-08-26 18:44         ` Jeff King
2019-08-25  8:10     ` [PATCH 2/2] fast-import: duplicate into history rather than passing ownership Jeff King
2019-08-25 10:02       ` Mike Hommey
2019-08-25 14:21         ` René Scharfe [this message]
2019-08-26 18:42           ` Jeff King
2019-08-26 15:36     ` [PATCH 0/2] fast-import input string handling bugs Junio C Hamano
2019-08-26 19:18     ` Elijah Newren
2019-08-25 12:35 ` [PATCH] fast-import: Reinitialize command_buf rather than detach it René Scharfe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=248c5f9f-ba44-6dec-6f30-f7d193bc22bb@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mh@glandium.org \
    --cc=newren@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).