From: Liu Yubao Date: Tue, 02 Dec 2008 01:55:05 GMT Subject: [PATCH 3/5] optimize parse_sha1_header() a little by detecting object type Message-ID: <49349579.2030506@gmail.com> In-Reply-To: <7voczws3np.fsf@gitster.siamese.dyndns.org> Signed-off-by: Liu Yubao --- sha1_file.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index dccc455..79062f0 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1099,7 +1099,8 @@ static void *map_sha1_file(const unsigned char *sha1, unsigned long *size) if (!fstat(fd, &st)) { *size = xsize_t(st.st_size); - map = xmmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0); + if (*size > 0) + map = xmmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0); } close(fd); } @@ -1257,6 +1258,8 @@ static int parse_sha1_header(const char *hdr, unsigned long length, unsigned lon * terminating '\0' that we add), and is followed by * a space, at least one byte for size, and a '\0'. */ + if ('b' != *hdr && 'c' != *hdr && 't' != *hdr) /* blob/commit/tag/tree */ + return -1; i = 0; while (hdr < hdr_end - 2) { char c = *hdr++; -- 1.6.1.rc1.5.gde86c