@matheusbsbs / matheus-bagliano / commits / b925410d10
Fork 0

pack-objects: thin pack micro-optimization.

Since we sort objects by type, hash, preferredness and then size, after we have a delta against preferred base, there is no point trying a delta with non-preferred base. This seems to save expensive calls to diff-delta and it also seems to save the output space as well. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 22, 2006 at 21:45 UTC b925410d10fce5e0d4182847f99e8c2df048bde1
1 file changed +10 -6
pack-objects.c
+10 -6
@@ -447,7 +447,7 @@ static int add_object_entry(const unsigned char *sha1, const char *name, int exc
447 struct packed_git *p;
448 unsigned int found_offset = 0;
449 struct packed_git *found_pack = NULL;
450 - int ix;
450 + int ix, status = 0;
451
452 if (!exclude) {
453 for (p = packed_git; p; p = p->next) {
@@ -493,6 +493,7 @@ static int add_object_entry(const unsigned char *sha1, const char *name, int exc
493 die("internal error in object hashing.");
494 object_ix[-1 - ix] = idx + 1;
495 }
496 + status = 1;
497
498 already_added:
499 if (exclude)
@@ -503,7 +504,7 @@ static int add_object_entry(const unsigned char *sha1, const char *name, int exc
504 entry->in_pack_offset = found_offset;
505 }
506 }
506 - return 1;
507 + return status;
508 }
509
510 static void add_pbase_tree(struct tree_desc *tree)
@@ -521,7 +522,10 @@ static void add_pbase_tree(struct tree_desc *tree)
522 continue;
523 if (sha1_object_info(sha1, type, &size))
524 continue;
524 - add_object_entry(sha1, name, 1);
525 +
526 + if (!add_object_entry(sha1, name, 1))
527 + continue;
528 +
529 if (!strcmp(type, "tree")) {
530 struct tree_desc sub;
531 void *elem;
@@ -543,8 +547,8 @@ static void add_preferred_base(unsigned char *sha1)
547 tree.buf = elem;
548 if (!tree.buf)
549 return;
546 - add_object_entry(sha1, "", 1);
547 - add_pbase_tree(&tree);
550 + if (add_object_entry(sha1, "", 1))
551 + add_pbase_tree(&tree);
552 free(elem);
553 }
554
@@ -774,7 +778,7 @@ static int try_delta(struct unpacked *cur, struct unpacked *old, unsigned max_de
778 * already have a delta based on preferred
779 * one is pointless.
780 */
777 - return 0;
781 + return -1;
782 }
783 else if (!old_preferred)
784 max_size = cur_entry->delta_size-1;