Re: [PATCH 1/3] pretty: support "mboxrd" output format

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

 



Eric Sunshine <sunshine@xxxxxxxxxxxxxx> writes:

> On Thu, Jun 2, 2016 at 3:51 AM, Eric Wong <e@xxxxxxxxx> wrote:
>> Eric Wong <e@xxxxxxxxx> wrote:
>>> Eric Sunshine <sunshine@xxxxxxxxxxxxxx> wrote:
>>> > On Tue, May 31, 2016 at 3:45 AM, Eric Wong <e@xxxxxxxxx> wrote:
>>> > > Eric Sunshine <sunshine@xxxxxxxxxxxxxx> 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.
>
> 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.

This is meant to be a replacement for the original that uses
regexec(), which in turn means the string we are checking is
guaranteed to be NUL terminated, right?

	static int is_mboxrd_from(const char *line) {
	        return starts_with(line + strspn(line, ">"), "From ");
	}

is sufficiently high-level that no longer is scary, hopefully?

I agree with you that regexec() is way overkill for something small
and simple like this.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[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]