Skip to content

Commit

Permalink
pack-object: slightly more efficient
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
Nicolas Pitre authored and Junio C Hamano committed May 15, 2006
1 parent 4e8da19 commit ff45715
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions delta.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ create_delta_index(const void *buf, unsigned long bufsize);

/*
* free_delta_index: free the index created by create_delta_index()
*
* Given pointer must be what create_delta_index() returned, or NULL.
*/
extern void free_delta_index(struct delta_index *index);

Expand Down
15 changes: 8 additions & 7 deletions pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit ff45715

Please sign in to comment.