Commit 7132150ddf7a883c1f12a89c2518c1a07c0dc94c

Carlos Martín Nieto 2015-11-14T23:46:21

tree: avoid advancing over the filename multiple times We've already looked at the filename with `memchr()` and then used `strlen()` to allocate the entry. We already know how much we have to advance to get to the object id, so add the filename length instead of looking at each byte again.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/src/tree.c b/src/tree.c
index bdd1766..3504452 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -414,10 +414,8 @@ int git_tree__parse(void *_tree, git_odb_object *odb_obj)
 			entry->attr = attr;
 		}
 
-		while (buffer < buffer_end && *buffer != 0)
-			buffer++;
-
-		buffer++;
+		/* Advance to the ID just after the path */
+		buffer += entry->filename_len + 1;
 
 		git_oid_fromraw(&entry->oid, (const unsigned char *)buffer);
 		buffer += GIT_OID_RAWSZ;