git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: "Jakub Narębski" <jnareb@gmail.com>, "Git List" <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 2/2] commit: don't check for space twice when looking for header
Date: Mon, 27 Feb 2017 23:54:22 +0100	[thread overview]
Message-ID: <cd9f3874-7428-9906-f805-31fe4661d4b6@web.de> (raw)
In-Reply-To: <1dd0884c-032c-fb04-67f6-8b181fd65eea@gmail.com>

Am 27.02.2017 um 23:27 schrieb Jakub Narębski:
> W dniu 25.02.2017 o 20:27, René Scharfe pisze:
>> 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.
>>
>> Signed-off-by: Rene Scharfe <l.s.r@web.de>
>> ---
>>  commit.c | 18 ++++++++----------
>>  1 file changed, 8 insertions(+), 10 deletions(-)
>>
>> diff --git a/commit.c b/commit.c
>> index 173c6d3818..fab8269731 100644
>> --- a/commit.c
>> +++ b/commit.c
>> @@ -1308,11 +1308,11 @@ void for_each_mergetag(each_mergetag_fn fn, struct commit *commit, void *data)
>>
>>  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)));
>
> I agree (for what it is worth from me) with the rest of changes,
> but I think current code is better self-documenting for this
> function.

Having a function that is given a buffer/length pair and accessing the 
byte after it raises questions, though. :)

Nicer than keeping the space would be to use excluded_header_field() for 
standard headers as well as a next step, I think -- but that would be a 
bit slower.

>
>>  }
>>
>>  static int excluded_header_field(const char *field, size_t len, const char **exclude)
>> @@ -1322,8 +1322,7 @@ static int excluded_header_field(const char *field, size_t len, const char **exc
>>
>>  	while (*exclude) {
>>  		size_t xlen = strlen(*exclude);
>> -		if (len == xlen &&
>> -		    !memcmp(field, *exclude, xlen) && field[xlen] == ' ')
>> +		if (len == xlen && !memcmp(field, *exclude, xlen))
>>  			return 1;
>>  		exclude++;
>>  	}
>> @@ -1357,9 +1356,8 @@ static struct commit_extra_header *read_commit_extra_header_lines(
>>  		eof = memchr(line, ' ', next - line);
>>  		if (!eof)
>>  			eof = next;
>> -
>> -		if (standard_header_field(line, eof - line) ||
>> -		    excluded_header_field(line, eof - line, exclude))
>> +		else if (standard_header_field(line, eof - line) ||
>> +			 excluded_header_field(line, eof - line, exclude))
>>  			continue;
>>
>>  		it = xcalloc(1, sizeof(*it));
>>
>

  reply	other threads:[~2017-02-27 22:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-25 19:21 [PATCH 1/2] commit: be more precise when searching for headers René Scharfe
2017-02-25 19:27 ` [PATCH 2/2] commit: don't check for space twice when looking for header René Scharfe
2017-02-25 20:15   ` Jeff King
2017-02-25 21:39     ` René Scharfe
2017-02-25 21:51       ` Jeff King
2017-02-27 22:27   ` Jakub Narębski
2017-02-27 22:54     ` René Scharfe [this message]
2017-02-25 20:12 ` [PATCH 1/2] commit: be more precise when searching for headers Jeff King
2017-02-27 19:18 ` Junio C Hamano

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=cd9f3874-7428-9906-f805-31fe4661d4b6@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jnareb@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).