From: Jason at zx2c4.com (Jason A. Donenfeld)
Subject: [PATCH] ui-refs.c: Simplify and inline cmp_age()
Date: Thu, 20 Feb 2014 20:00:13 +0100 [thread overview]
Message-ID: <CAHmME9qxhj1BiDmqc38ZxHu_u2H8w-xPX--NSPzB1p4gKM-JhQ@mail.gmail.com> (raw)
In-Reply-To: <20140204200757.4882.92393@typhoon.lan>
I haven't had any time to work through all the logic for why this
might be the case. Are any volunteers who can triple check that the
change in logic here is not an issue? I'd like to be extra certain
before merging this.
On Tue, Feb 4, 2014 at 9:07 PM, Lukas Fleischer <cgit at cryptocrack.de> wrote:
>
> On Tue, 04 Feb 2014 at 20:22:05, Lukas Fleischer wrote:
> > In comparison functions, only the sign of the return value matters -- no
> > need to have extra checks to ensure the return value always is +/-1 when
> > the actual parameters differ. After removing all the checks, the
> > function body boils down to
> >
> > return age2 - age1;
> >
> > so we can as well replace all invocations with that subtraction.
> >
> > Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
> > ---
> > ui-refs.c | 18 ++----------------
> > 1 file changed, 2 insertions(+), 16 deletions(-)
> >
>
> Lars, we're not quite sure whether this patch is correct. I can't see
> where the version not having the extra checks behaves different from the
> original function but we might be missing something. Do you remember why
> you implemented cmp_age() like this in the first place?
>
> Please Cc Jason when replying. Thanks!
>
> > diff --git a/ui-refs.c b/ui-refs.c
> > index 147b665..8a4ce74 100644
> > --- a/ui-refs.c
> > +++ b/ui-refs.c
> > @@ -11,20 +11,6 @@
> > #include "html.h"
> > #include "ui-shared.h"
> >
> > -static int cmp_age(int age1, int age2)
> > -{
> > - if (age1 != 0 && age2 != 0)
> > - return age2 - age1;
> > -
> > - if (age1 == 0 && age2 == 0)
> > - return 0;
> > -
> > - if (age1 == 0)
> > - return +1;
> > -
> > - return -1;
> > -}
> > -
> > static int cmp_ref_name(const void *a, const void *b)
> > {
> > struct refinfo *r1 = *(struct refinfo **)a;
> > @@ -38,7 +24,7 @@ static int cmp_branch_age(const void *a, const void *b)
> > struct refinfo *r1 = *(struct refinfo **)a;
> > struct refinfo *r2 = *(struct refinfo **)b;
> >
> > - return cmp_age(r1->commit->committer_date, r2->commit->committer_date);
> > + return r2->commit->committer_date - r1->commit->committer_date;
> > }
> >
> > static int get_ref_age(struct refinfo *ref)
> > @@ -59,7 +45,7 @@ static int cmp_tag_age(const void *a, const void *b)
> > struct refinfo *r1 = *(struct refinfo **)a;
> > struct refinfo *r2 = *(struct refinfo **)b;
> >
> > - return cmp_age(get_ref_age(r1), get_ref_age(r2));
> > + return get_ref_age(r2)- get_ref_age(r1);
> > }
> >
> > static int print_branch(struct refinfo *ref)
> > --
> > 1.8.5.3
> >
> > _______________________________________________
> > CGit mailing list
> > CGit at lists.zx2c4.com
> > http://lists.zx2c4.com/mailman/listinfo/cgit
prev parent reply other threads:[~2014-02-20 19:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-04 19:22 cgit
2014-02-04 19:26 ` Jason
2014-02-04 19:27 ` Jason
2014-02-04 19:27 ` cgit
2014-02-04 19:36 ` cgit
[not found] ` <20140204200757.4882.92393@typhoon.lan>
2014-02-20 19:00 ` Jason [this message]
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=CAHmME9qxhj1BiDmqc38ZxHu_u2H8w-xPX--NSPzB1p4gKM-JhQ@mail.gmail.com \
--to=cgit@lists.zx2c4.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).