Re: [PATCH 1/2] entry.c: convert checkout_entry to use strbuf
- From
Jeff King <peff@peff.net>
- Date
- Oct 23, 2013, 18:10 UTC
- Message-ID
- <20131023181057.GA7950@sigill.intra.peff.net>
- In-Reply-To
- <xmqqa9hzrh9k.fsf@gitster.dls.corp.google.com>
On Wed, Oct 23, 2013 at 11:09:27AM -0700, Junio C Hamano wrote:
Show 21 quoted lines
> > This is not something you introduced, but while we are here, you may > > want to use ce->namelen, which would be a little faster than treating it > > as a string (especially for strbuf, as it can then know up front how big > > the size is). > > Hmmmm, do you mean something like this on top? > > diff --git a/entry.c b/entry.c > index d955af5..0d48292 100644 > --- a/entry.c > +++ b/entry.c > @@ -246,7 +246,9 @@ int checkout_entry(struct cache_entry *ce, > return write_entry(ce, topath, state, 1); > > strbuf_reset(&path_buf); > - strbuf_addf(&path_buf, "%.*s%s", state->base_dir_len, state->base_dir, ce->name); > + strbuf_addf(&path_buf, "%.*s%.*s", > + state->base_dir_len, state->base_dir, > + ce_namelen(ce), ce->name); > path = path_buf.buf; > len = path_buf.len;
Yes, though I actually find Erik's version with two separate strbuf_add invocations slightly more readable (it _could_ result in two allocations, but again, we are amortizing the growth over many calls anyway, so most of them will not need to grow the buffer at all).
-Peff
-- -- *** Please reply-to-all at all times *** *** (do not pretend to know who is subscribed and who is not) *** *** Please avoid top-posting. *** The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free. You received this message because you are subscribed to the Google Groups "msysGit" group. To post to this group, send email to msysgit@googlegroups.com To unsubscribe from this group, send email to msysgit+unsubscribe@googlegroups.com For more options, and view previous threads, visit this group at http://groups.google.com/group/msysgit?hl=en_US?hl=en --- You received this message because you are subscribed to the Google Groups "msysGit" group. To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.