Skip to content

Commit d6bc22e

Browse files
committed
Merge branch 'rs/commit-parsing-optim' into maint
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
2 parents 93abd17 + b072504 commit d6bc22e

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

commit.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,11 +1308,11 @@ void for_each_mergetag(each_mergetag_fn fn, struct commit *commit, void *data)
13081308

13091309
static inline int standard_header_field(const char *field, size_t len)
13101310
{
1311-
return ((len == 4 && !memcmp(field, "tree ", 5)) ||
1312-
(len == 6 && !memcmp(field, "parent ", 7)) ||
1313-
(len == 6 && !memcmp(field, "author ", 7)) ||
1314-
(len == 9 && !memcmp(field, "committer ", 10)) ||
1315-
(len == 8 && !memcmp(field, "encoding ", 9)));
1311+
return ((len == 4 && !memcmp(field, "tree", 4)) ||
1312+
(len == 6 && !memcmp(field, "parent", 6)) ||
1313+
(len == 6 && !memcmp(field, "author", 6)) ||
1314+
(len == 9 && !memcmp(field, "committer", 9)) ||
1315+
(len == 8 && !memcmp(field, "encoding", 8)));
13161316
}
13171317

13181318
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
13221322

13231323
while (*exclude) {
13241324
size_t xlen = strlen(*exclude);
1325-
if (len == xlen &&
1326-
!memcmp(field, *exclude, xlen) && field[xlen] == ' ')
1325+
if (len == xlen && !memcmp(field, *exclude, xlen))
13271326
return 1;
13281327
exclude++;
13291328
}
@@ -1354,12 +1353,11 @@ static struct commit_extra_header *read_commit_extra_header_lines(
13541353
strbuf_reset(&buf);
13551354
it = NULL;
13561355

1357-
eof = strchr(line, ' ');
1358-
if (next <= eof)
1356+
eof = memchr(line, ' ', next - line);
1357+
if (!eof)
13591358
eof = next;
1360-
1361-
if (standard_header_field(line, eof - line) ||
1362-
excluded_header_field(line, eof - line, exclude))
1359+
else if (standard_header_field(line, eof - line) ||
1360+
excluded_header_field(line, eof - line, exclude))
13631361
continue;
13641362

13651363
it = xcalloc(1, sizeof(*it));

0 commit comments

Comments
 (0)