From: Markus Mayer <code@mmayer.net>
To: Alex Colomar <alx.manpages@gmail.com>
Cc: CGIT List <cgit@lists.zx2c4.com>
Subject: Re: [PATCH 1/1] global: provide memrchr implementation for macOS
Date: Fri, 27 Jan 2023 16:35:07 -0800 [thread overview]
Message-ID: <CANEuBv7utpNdksKkv76yztSuUrOW-qhjYVQv_SwzfLJb7Z5U0A@mail.gmail.com> (raw)
In-Reply-To: <fe46d404-8659-7260-63c1-38bbc9c1e5ad@gmail.com>
Hi Alex,
> This code seems overly complex to me. A do-while seems unintuitive when
> you're not performing at least 1 iteration, and having an if that is
> basically the same operation as the while condition seems weird. Maybe
> I'm missing something, but it looks like it can be written more readable as:
I have no objections to changing the code. For my initial submission,
I figured I'd use an implementation that comes directly from Apple's
own open source server. But if the consensus is to tweak the code to
make it smaller / faster / more readable, that's alright by me. I only
want CGIT to build on macOS. :-)
> void *
> memrchr(const void *s, int c, size_t n)
> {
> unsigned char ch;
> const unsigned char *cp;
>
> ch = c;
>
> cp = s;
> for (cp += n; n != 0; n--) {
> cp--;
> if (*cp == ch)
> return (void *) cp;
> }
>
> return NULL;
> }
Let me play around with this.
> Clang produces similar assembly code for both. GCC however produces
> smaller code for the for loop.
Thanks for the feedback.
Regards,
-Markus
next prev parent reply other threads:[~2023-01-28 0:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-27 23:15 [PATCH 0/1] cgit " Markus Mayer
2023-01-27 23:15 ` [PATCH 1/1] global: provide memrchr implementation " Markus Mayer
[not found] ` <fe46d404-8659-7260-63c1-38bbc9c1e5ad@gmail.com>
2023-01-28 0:35 ` Markus Mayer [this message]
[not found] ` <Y9R3X7bhwUAWofJ/@xps13>
2023-01-29 21:43 ` Markus Mayer
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=CANEuBv7utpNdksKkv76yztSuUrOW-qhjYVQv_SwzfLJb7Z5U0A@mail.gmail.com \
--to=code@mmayer.net \
--cc=alx.manpages@gmail.com \
--cc=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).