git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Quint Guvernator <quintus.public@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH] general style: replaces memcmp() with proper starts_with()
Date: Wed, 12 Mar 2014 13:08:03 -0700	[thread overview]
Message-ID: <xmqq61njkwnw.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <20140312194943.GA2912@sigill.intra.peff.net> (Jeff King's message of "Wed, 12 Mar 2014 15:49:44 -0400")

Jeff King <peff@peff.net> writes:

>> Blindly replacing starts_with() with !memcmp() in the above part is
>> a readability regression otherwise.
>
> I actually think the right solution is:
>
>   static inline int standard_header_field(const char *field, size_t len)
>   {
>           return mem_equals(field, len, "tree ") ||
>                  mem_equals(field, len, "parent ") ||
>                  ...;
>   }
>
> and the caller should tell us it's OK to look at field[len]:
>
>   standard_header_field(line, eof - line + 1)
>
> We could also omit the space from the standard_header_field.

Yes, that was what I had in mind.  The only reason why the callee
(over-)optimizes the "SP must follow these know keywords" part by
using the extra "len" parameter is because the caller has to do a
single strchr() to skip an arbitrary field name anyway so computing
"len" is essentially free.

> The caller
> just ran strchr() looking for the space, so we know that either it is
> there, or we are at the end of the line/buffer. Arguably a string like
> "parent\n" should be "a parent header with no data" (but right now it is
> not matched by this function). I'm not aware of an implementation that
> writes such a thing, but it seems to fall in the "be liberal in what you
> accept" category.

It is _not_ a standard header field, so it will be read by the logic
in the caller as a non-standard header field without getting lost.

  reply	other threads:[~2014-03-12 20:08 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-12 14:43 [PATCH] general style: replaces memcmp() with proper starts_with() Quint Guvernator
2014-03-12 17:56 ` Jeff King
2014-03-12 19:39   ` Junio C Hamano
2014-03-12 19:49     ` Jeff King
2014-03-12 20:08       ` Junio C Hamano [this message]
2014-03-12 21:14         ` Jeff King
2014-03-12 21:39           ` Jeff King
2014-03-12 22:06           ` Jeff King
2014-03-12 22:38             ` Junio C Hamano
2014-03-13  3:33               ` Quint Guvernator
2014-03-13 17:46                 ` Junio C Hamano
2014-03-14  4:57                 ` Jeff King
2014-03-14 14:51                   ` Quint Guvernator
2014-03-14 16:56                     ` Junio C Hamano
2014-03-12 20:51     ` René Scharfe
2014-03-12 21:16       ` David Kastrup
2014-03-12 21:45         ` René Scharfe
2014-03-12 20:52     ` David Kastrup
2014-03-12 22:37   ` Junio C Hamano
2014-03-13  6:27     ` David Kastrup
2014-03-13 17:47       ` Junio C Hamano
2014-03-13 17:55         ` Jeff King

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq61njkwnw.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=quintus.public@gmail.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).