From: Eric Sunshine <sunshine@sunshineco.com>
To: Eric Wong <e@80x24.org>
Cc: Git List <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 1/3] pretty: support "mboxrd" output format
Date: Fri, 3 Jun 2016 18:22:02 -0400 [thread overview]
Message-ID: <CAPig+cTLVXJBn00aco0vC9oFvZuchTgtNXtGGjpLPx1LwRZz4Q@mail.gmail.com> (raw)
In-Reply-To: <20160602075125.GA19551@dcvr.yhbt.net>
[cc:+junio]
On Thu, Jun 2, 2016 at 3:51 AM, Eric Wong <e@80x24.org> wrote:
> Eric Wong <e@80x24.org> wrote:
>> Eric Sunshine <sunshine@sunshineco.com> wrote:
>> > On Tue, May 31, 2016 at 3:45 AM, Eric Wong <e@80x24.org> wrote:
>> > > Eric Sunshine <sunshine@sunshineco.com> wrote:
>> > >> I wonder if hand-coding, rather than using a regex, could be an improvement:
>> > >>
>> > >> static int is_mboxrd_from(const char *s, size_t n)
>> > >> {
>> > >> size_t f = strlen("From ");
>> > >> const char *t = s + n;
>> > >>
>> > >> while (s < t && *s == '>')
>> > >> s++;
>> > >> return t - s >= f && !memcmp(s, "From ", f);
>> > >> }
>> > >>
>> > >> or something.
>> > >
>> > > Yikes. I mostly work in high-level languages and do my best to
>> > > avoid string parsing in C; so that scares me. A lot.
>> >
>> > The hand-coded is_mboxrd_from() above is pretty much idiomatic C and
>> > (I think) typical of how such a function would be coded in Git itself,
>> > so it looks normal and easy to grok to me (but, of course, I'm
>> > probably biased since I wrote it).
>
> For reference, here is the gfrom function from qmail (gfrom.c,
> source package netqmail-1.06 in Debian, reformatted git style)
>
> int gfrom(char *s, int len)
> {
> while ((len > 0) && (*s == '>')) {
> ++s;
> --len;
> }
>
> return (len >= 5) && !str_diffn(s, "From ", 5);
> }
Seems less idiomatic and less like what we might see elsewhere in the
Git codebase, but that's subjective. Functionally, it appears correct.
> Similar to yours, but a several small things improves
> readability for me:
>
> * the avoidance of subtraction from the "return" conditional
> * s/n/len/ variable name
Idiomatic C code favors concise names such as 'i', 'j', or 'n', for
instance, but I don't care strongly.
> * extra parentheses
Unnecessary syntactic noise (consuming reviewer brain cycles).
> * removal of "t" variable (t for "terminal/termination"?)
Heh, no, just the next letter after 's'. Again, just an idiom, as 'i',
'j', 'k' are often used for integers, 's' and 't' are common for
strings.
> str_diffn is memcmp-like, I assume. My eyes glazed over
> when I saw that function implemented in str_diffn.c, too.
>
> Just thinking out loud, with sufficient tests I could go with
> either. Will reroll when/if I get the chance tomorrow.
As mentioned above, it's all subjective and, of course, I have a bias
toward the example I provided, but don't otherwise feel strongly about
it. I do, however, like the idea of using a simple hand-coded matching
function over the regex (but no so much that I would complain about
it). Use whatever you and Junio feel is appropriate.
next prev parent reply other threads:[~2016-06-03 22:22 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-30 23:21 [RFC/PATCH 0/3] support mboxrd format Eric Wong
2016-05-30 23:21 ` [PATCH 1/3] pretty: support "mboxrd" output format Eric Wong
2016-05-31 3:40 ` Eric Sunshine
2016-05-31 7:45 ` Eric Wong
2016-05-31 18:10 ` Eric Sunshine
2016-05-31 18:29 ` Eric Wong
2016-05-31 20:12 ` Eric Sunshine
2016-05-31 20:19 ` Eric Sunshine
2016-06-02 7:51 ` Eric Wong
2016-06-03 22:22 ` Eric Sunshine [this message]
2016-06-03 22:36 ` Junio C Hamano
2016-06-03 22:59 ` Eric Sunshine
2016-06-03 23:42 ` Junio C Hamano
2016-06-04 0:02 ` Eric Sunshine
2016-06-04 0:19 ` Eric Sunshine
2016-06-04 2:03 ` Junio C Hamano
2016-05-30 23:21 ` [PATCH 2/3] mailsplit: support unescaping mboxrd messages Eric Wong
2016-05-30 23:21 ` [PATCH 3/3] am: support --patch-format=mboxrd Eric Wong
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=CAPig+cTLVXJBn00aco0vC9oFvZuchTgtNXtGGjpLPx1LwRZz4Q@mail.gmail.com \
--to=sunshine@sunshineco.com \
--cc=e@80x24.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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).