@matheusbsbs / matheus-bagliano / commits / 8a5a8d6c97
Fork 0

pack-objects: optimize preferred base handling a bit

Let's avoid some cycles when there is no base to test against, and avoid unnecessary object lookups. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nicolas Pitre committed Apr 16, 2007 at 12:28 UTC 8a5a8d6c97e36dbd95361eab1109e4380fe45df4
1 file changed +12 -15
builtin-pack-objects.c
+12 -15
@@ -959,22 +959,21 @@ static void add_pbase_object(struct tree_desc *tree,
959 const char *fullname)
960 {
961 struct name_entry entry;
962 + int cmp;
963
964 while (tree_entry(tree,&entry)) {
964 - unsigned long size;
965 - enum object_type type;
966 -
967 - if (tree_entry_len(entry.path, entry.sha1) != cmplen ||
968 - memcmp(entry.path, name, cmplen) ||
969 - !has_sha1_file(entry.sha1) ||
970 - (type = sha1_object_info(entry.sha1, &size)) < 0)
965 + cmp = tree_entry_len(entry.path, entry.sha1) != cmplen ? 1 :
966 + memcmp(name, entry.path, cmplen);
967 + if (cmp > 0)
968 continue;
969 + if (cmp < 0)
970 + return;
971 if (name[cmplen] != '/') {
972 unsigned hash = name_hash(fullname);
973 add_object_entry(entry.sha1, hash, 1);
974 return;
975 }
977 - if (type == OBJ_TREE) {
976 + if (S_ISDIR(entry.mode)) {
977 struct tree_desc sub;
978 struct pbase_tree_cache *tree;
979 const char *down = name+cmplen+1;
@@ -1034,15 +1033,15 @@ static int check_pbase_path(unsigned hash)
1033 static void add_preferred_base_object(const char *name, unsigned hash)
1034 {
1035 struct pbase_tree *it;
1037 - int cmplen = name_cmp_len(name);
1036 + int cmplen;
1037
1039 - if (check_pbase_path(hash))
1038 + if (!num_preferred_base || check_pbase_path(hash))
1039 return;
1040
1041 + cmplen = name_cmp_len(name);
1042 for (it = pbase_tree; it; it = it->next) {
1043 if (cmplen == 0) {
1044 - hash = name_hash("");
1045 - add_object_entry(it->pcache.sha1, hash, 1);
1044 + add_object_entry(it->pcache.sha1, 0, 1);
1045 }
1046 else {
1047 struct tree_desc tree;
@@ -1587,9 +1586,7 @@ static void read_object_list_from_stdin(void)
1586
1587 static void show_commit(struct commit *commit)
1588 {
1590 - unsigned hash = name_hash("");
1591 - add_preferred_base_object("", hash);
1592 - add_object_entry(commit->object.sha1, hash, 0);
1589 + add_object_entry(commit->object.sha1, 0, 0);
1590 }
1591
1592 static void show_object(struct object_array_entry *p)