commit: don't check for space twice when looking for header
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Feb 25, 2017 at 20:27 UTC
b072504ce17564bcfd8cb82d6e3948720626065d
1 file changed
+8
-10
commit.c
+8
-10
@@ -1308,11 +1308,11 @@ void for_each_mergetag(each_mergetag_fn fn, struct commit *commit, void *data)
1308
1309
static inline int standard_header_field(const char *field, size_t len)
1310
{
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)));
1316
}
1317
1318
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
1322
1323
while (*exclude) {
1324
size_t xlen = strlen(*exclude);
1325
- if (len == xlen &&
1326
- !memcmp(field, *exclude, xlen) && field[xlen] == ' ')
1325
+ if (len == xlen && !memcmp(field, *exclude, xlen))
1326
return 1;
1327
exclude++;
1328
}
@@ -1357,9 +1356,8 @@ static struct commit_extra_header *read_commit_extra_header_lines(
1356
eof = memchr(line, ' ', next - line);
1357
if (!eof)
1358
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))
1361
continue;
1362
1363
it = xcalloc(1, sizeof(*it));