Re: [PATCH 1/1] general style: replaces memcmp() with starts_with()
- From
Jeff King <peff@peff.net>
- Date
- Mar 17, 2014, 23:01 UTC
- Message-ID
- <20140317230139.GB19578@sigill.intra.peff.net>
- In-Reply-To
- <xmqqob14a14s.fsf@gitster.dls.corp.google.com>
On Mon, Mar 17, 2014 at 03:52:51PM -0700, Junio C Hamano wrote:
Show 15 quoted lines
> > diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c > > index 3e1d5c3..4135980 100644 > > --- a/builtin/for-each-ref.c > > +++ b/builtin/for-each-ref.c > > @@ -193,7 +193,7 @@ static int verify_format(const char *format) > > at = parse_atom(sp + 2, ep); > > cp = ep + 1; > > > > - if (!memcmp(used_atom[at], "color:", 6)) > > + if (starts_with(used_atom[at], "color:")) > > need_color_reset_at_eol = !!strcmp(used_atom[at], color_reset); > > } > > return 0; > > Good.
Actually, I found this one confusing. We are looking for "color:", but if we find it, we _don't_ skip past and look at what comes after. Instead, we compare the whole string. Which works because color_reset actually contains "color:reset", and we end up just re-comparing the first bit of the string. So the memcmp here is redundant, and this can simply become:
need_color_reset_at_eol = !!strcmp(used_atom[at], color_reset);
Or am I missing something?
-Peff