git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "René Scharfe" <l.s.r@web.de>
Cc: Mike Hommey <mh@glandium.org>, 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: Mon, 26 Aug 2019 14:42:53 -0400	[thread overview]
Message-ID: <20190826184252.GC23399@sigill.intra.peff.net> (raw)
In-Reply-To: <248c5f9f-ba44-6dec-6f30-f7d193bc22bb@web.de>

On Sun, Aug 25, 2019 at 04:21:54PM +0200, René Scharfe wrote:

> > 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..

Yep. I actually started to write xmemdupz() originally then decided it
was unnecessarily verbose and a premature optimization.

I wondered after this exchange whether something like:

  char *strbuf_dup(const struct strbuf *sb)
  {
	return xmemdupz(sb->buf, sb->len);
  }

would be a useful general helper. Grepping around it doesn't seem like
there are a lot of candidates.

If we really wanted to micro-optimize, we could have cmd_hist store
strbufs, and then we could reuse the same buffers over and over without
re-allocating. And use strbuf_addbuf(&cmd_hist.buf, &command_buf). :)

-Peff

  reply	other threads:[~2019-08-26 18:42 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
2019-08-26 18:42           ` Jeff King [this message]
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=20190826184252.GC23399@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    --cc=mh@glandium.org \
    --cc=newren@gmail.com \
    /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).