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>
Nicolas Pitre committed
May 15, 2006 at 13:47 UTC
ff45715ce50b80ab16ee0d0dc7fff0c47a51959a
2 files changed
+10
-7
delta.h
+2
@@ -18,6 +18,8 @@ create_delta_index(const void *buf, unsigned long bufsize);
18
19
/*
20
* free_delta_index: free the index created by create_delta_index()
21
+ *
22
+ * Given pointer must be what create_delta_index() returned, or NULL.
23
*/
24
extern void free_delta_index(struct delta_index *index);
25
pack-objects.c
+8
-7
@@ -1105,17 +1105,14 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1105
1106
if (entry->size < 50)
1107
continue;
1108
- if (n->index)
1109
- free_delta_index(n->index);
1108
+ free_delta_index(n->index);
1109
+ n->index = NULL;
1110
free(n->data);
1111
n->entry = entry;
1112
n->data = read_sha1_file(entry->sha1, type, &size);
1113
if (size != entry->size)
1114
die("object %s inconsistent object length (%lu vs %lu)",
1115
sha1_to_hex(entry->sha1), size, entry->size);
1116
- n->index = create_delta_index(n->data, size);
1117
- if (!n->index)
1118
- die("out of memory");
1116
1117
j = window;
1118
while (--j > 0) {
@@ -1135,6 +1132,11 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1132
*/
1133
if (entry->delta && depth <= entry->depth)
1134
continue;
1135
+
1136
+ n->index = create_delta_index(n->data, size);
1137
+ if (!n->index)
1138
+ die("out of memory");
1139
+
1140
idx++;
1141
if (idx >= window)
1142
idx = 0;
@@ -1144,8 +1146,7 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1146
fputc('\n', stderr);
1147
1148
for (i = 0; i < window; ++i) {
1147
- if (array[i].index)
1148
- free_delta_index(array[i].index);
1149
+ free_delta_index(array[i].index);
1150
free(array[i].data);
1151
}
1152
free(array);