Re: [PATCH] for-each-ref: remove multiple xstrdup() in get_short_ref()
- From
Bert Wesarg <bert.wesarg@googlemail.com>
- Date
- Apr 7, 2009, 07:54 UTC
- Message-ID
- <36ca99e90904070054y3bbd21e0g44548162e71f3a13@mail.gmail.com>
- In-Reply-To
- <20090407074435.GB7327@coredump.intra.peff.net>
On Tue, Apr 7, 2009 at 09:44, Jeff King <peff@peff.net> wrote:
Show 8 quoted lines
> On Tue, Apr 07, 2009 at 09:33:19AM +0200, Bert Wesarg wrote: > >> Now that get_short_ref() always return an malloced string, consolidate to >> one xstrcpy() call. > > Makes sense to squash in on top of what I have. But I think it actually > is pretty easy to always return a pointer into the existing string > (patch based on current master):
Yes, thats probably a good idea. The caller can always do a xstrdup(get_short_ref(ref)).
Show 8 quoted lines
> @@ -637,12 +637,14 @@ static char *get_short_ref(struct refinfo *ref)
> * short name is non-ambiguous if all previous rules
> * haven't resolved to a valid ref
> */
> - if (j == i)
> - return short_name;
> + if (j == i) {
> + ref += strlen(ref) - strlen(short_name);we have strlen(short_name) in short_name_len already.
Bert