summaryrefslogtreecommitdiff
path: root/pack-objects.c
diff options
context:
space:
mode:
authorNicolas Pitre <nico@cam.org>2006-05-15 13:47:16 -0400
committerJunio C Hamano <junkio@cox.net>2006-05-15 12:32:13 -0700
commitff45715ce50b80ab16ee0d0dc7fff0c47a51959a (patch)
treeaab49d4b562b46c146524f0f9729037666b79380 /pack-objects.c
parent4e8da1958111796d55ad63b229ebd3ae6c54bf87 (diff)
downloadgit-ff45715ce50b80ab16ee0d0dc7fff0c47a51959a.tar.gz
pack-object: slightly more efficient
Avoid creating a delta index for objects with maximum depth since they are not going to be used as delta base anyway. This also reduce peak memory usage slightly as the current object's delta index is not useful until the next object in the loop is considered for deltification. This saves a bit more than 1% on CPU usage. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'pack-objects.c')
-rw-r--r--pack-objects.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/pack-objects.c b/pack-objects.c
index 526c090c61..b430b02cf7 100644
--- a/pack-objects.c
+++ b/pack-objects.c
@@ -1105,17 +1105,14 @@ static void find_deltas(struct object_entry **list, int window, int depth)
if (entry->size < 50)
continue;
- if (n->index)
- free_delta_index(n->index);
+ free_delta_index(n->index);
+ n->index = NULL;
free(n->data);
n->entry = entry;
n->data = read_sha1_file(entry->sha1, type, &size);
if (size != entry->size)
die("object %s inconsistent object length (%lu vs %lu)",
sha1_to_hex(entry->sha1), size, entry->size);
- n->index = create_delta_index(n->data, size);
- if (!n->index)
- die("out of memory");
j = window;
while (--j > 0) {
@@ -1135,6 +1132,11 @@ static void find_deltas(struct object_entry **list, int window, int depth)
*/
if (entry->delta && depth <= entry->depth)
continue;
+
+ n->index = create_delta_index(n->data, size);
+ if (!n->index)
+ die("out of memory");
+
idx++;
if (idx >= window)
idx = 0;
@@ -1144,8 +1146,7 @@ static void find_deltas(struct object_entry **list, int window, int depth)
fputc('\n', stderr);
for (i = 0; i < window; ++i) {
- if (array[i].index)
- free_delta_index(array[i].index);
+ free_delta_index(array[i].index);
free(array[i].data);
}
free(array);