diff options
| author | Junio C Hamano <gitster@pobox.com> | 2017-03-10 13:24:22 -0800 | 
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2017-03-10 13:24:22 -0800 | 
| commit | 98c96f8bffe315dc82f694d50a4c83567a4ee133 (patch) | |
| tree | c6a9bfb7058090da246fba19b094db72f7994dea /commit.c | |
| parent | 11cfc0ef9674e55019047c0d4b4deb42877cee38 (diff) | |
| parent | b072504ce17564bcfd8cb82d6e3948720626065d (diff) | |
| download | git-98c96f8bffe315dc82f694d50a4c83567a4ee133.tar.gz | |
Merge branch 'rs/commit-parsing-optim'
The code that parses header fields in the commit object has been
updated for (micro)performance and code hygiene.
* rs/commit-parsing-optim:
  commit: don't check for space twice when looking for header
  commit: be more precise when searching for headers
Diffstat (limited to 'commit.c')
| -rw-r--r-- | commit.c | 22 | 
1 files changed, 10 insertions, 12 deletions
| @@ -1307,11 +1307,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)));  }  static int excluded_header_field(const char *field, size_t len, const char **exclude) @@ -1321,8 +1321,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++;  	} @@ -1353,12 +1352,11 @@ static struct commit_extra_header *read_commit_extra_header_lines(  		strbuf_reset(&buf);  		it = NULL; -		eof = strchr(line, ' '); -		if (next <= eof) +		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)); | 
