Re: [PATCH] refs.c: use skip_prefix() in prettify_refname()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 23, 2017 at 12:23 PM, Jeff King <peff@xxxxxxxx> wrote:
> On Thu, Mar 23, 2017 at 08:18:26PM +0100, René Scharfe wrote:
>
>> Am 23.03.2017 um 16:50 schrieb SZEDER Gábor:
>> > This eliminates three magic numbers.
>> >
>> > Signed-off-by: SZEDER Gábor <szeder.dev@xxxxxxxxx>
>> > ---
>> >  refs.c | 10 +++++-----
>> >  1 file changed, 5 insertions(+), 5 deletions(-)
>> >
>> > diff --git a/refs.c b/refs.c
>> > index e7606716d..0272e332c 100644
>> > --- a/refs.c
>> > +++ b/refs.c
>> > @@ -366,11 +366,11 @@ int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)
>> >
>> >  const char *prettify_refname(const char *name)
>> >  {
>> > -   return name + (
>> > -           starts_with(name, "refs/heads/") ? 11 :
>> > -           starts_with(name, "refs/tags/") ? 10 :
>> > -           starts_with(name, "refs/remotes/") ? 13 :
>> > -           0);
>> > +   if (skip_prefix(name, "refs/heads/", &name) ||
>> > +       skip_prefix(name, "refs/tags/", &name) ||
>> > +       skip_prefix(name, "refs/remotes/", &name))
>> > +           ; /* nothing */
>> > +   return name;
>>
>> Nice, but why add the "if" when it's doing nothing?
>
> It's short-circuiting in the conditional.

You do not need a conditional to short circuit things.
|| works outside an if, too. ;)

Anyway, maybe it's worth spelling it out with an if .. else if
cascade for readability?

After your comment of short-circuiting this code is pretty clear,
so maybe just a small comment would do?

Thanks,
Stefan

>
> -Peff




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]