git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] commit: don't check for space twice when looking for header

From
Jeff King <peff@peff.net>
Date
Feb 25, 2017, 20:15 UTC
Message-ID
<20170225201522.uan52fwey6zjosym@sigill.intra.peff.net>
In-Reply-To
<b1d5c882-38b8-dd2d-2e5f-aafb8dfada81@web.de>
On Sat, Feb 25, 2017 at 08:27:40PM +0100, René Scharfe wrote:
Show 5 quoted lines
> Both standard_header_field() and excluded_header_field() check if
> there's a space after the buffer that's handed to them.  We already
> check in the caller if that space is present.  Don't bother calling
> the functions if it's missing, as they are guaranteed to return 0 in
> that case, and remove the now redundant checks from them.

Makes sense, and I couldn't spot any errors in your logic or in the code.

Show 12 quoted lines
>  static inline int standard_header_field(const char *field, size_t len)
>  {
> -	return ((len == 4 && !memcmp(field, "tree ", 5)) ||
> -		(len == 6 && !memcmp(field, "parent ", 7)) ||
> -		(len == 6 && !memcmp(field, "author ", 7)) ||
> -		(len == 9 && !memcmp(field, "committer ", 10)) ||
> -		(len == 8 && !memcmp(field, "encoding ", 9)));
> +	return ((len == 4 && !memcmp(field, "tree", 4)) ||
> +		(len == 6 && !memcmp(field, "parent", 6)) ||
> +		(len == 6 && !memcmp(field, "author", 6)) ||
> +		(len == 9 && !memcmp(field, "committer", 9)) ||
> +		(len == 8 && !memcmp(field, "encoding", 8)));

Unrelated, but this could probably be spelled with a macro and strlen() to avoid the magic numbers. It would probably be measurably slower for a compiler which doesn't pre-compute strlen() on a string literal, though.

-Peff
Previous: René ScharfeNext: René Scharfe
Message 3 of 9 in “commit: be more precise when searching for headers”
  1. 1/2 commit: be more precise when searching for headersRené Scharfe, Feb 25, 2017
  2. 2/2 commit: don't check for space twice when looking for headerRené Scharfe, Feb 25, 2017
  3. Jeff KingFeb 25, 2017
  4. René ScharfeFeb 25, 2017
  5. Jeff KingFeb 25, 2017
  6. Jakub NarębskiFeb 27, 2017
  7. René ScharfeFeb 27, 2017
  8. Jeff KingFeb 25, 2017
  9. Junio C HamanoFeb 27, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.