Skip to content

Commit 108f530

Browse files
chriscoolgitster
authored andcommitted
pack-objects: move tree_depth into 'struct packing_data'
This reduces the size of 'struct object_entry' and therefore makes packing objects more efficient. This also renames cmp_tree_depth() into tree_depth_compare(), as it is more modern to have the name of the compare functions end with "compare". Helped-by: Jeff King <[email protected]> Helped-by: Duy Nguyen <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9eb0986 commit 108f530

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

builtin/pack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,8 +2716,8 @@ static void show_object(struct object *obj, const char *name, void *data)
27162716
depth++;
27172717

27182718
ent = packlist_find(&to_pack, obj->oid.hash, NULL);
2719-
if (ent && depth > ent->tree_depth)
2720-
ent->tree_depth = depth;
2719+
if (ent && depth > oe_tree_depth(&to_pack, ent))
2720+
oe_set_tree_depth(&to_pack, ent, depth);
27212721
}
27222722
}
27232723

delta-islands.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,23 @@ static void mark_remote_island_1(struct remote_island *rl, int is_core_island)
224224
island_counter++;
225225
}
226226

227-
static int cmp_tree_depth(const void *va, const void *vb)
227+
struct tree_islands_todo {
228+
struct object_entry *entry;
229+
unsigned int depth;
230+
};
231+
232+
static int tree_depth_compare(const void *a, const void *b)
228233
{
229-
struct object_entry *a = *(struct object_entry **)va;
230-
struct object_entry *b = *(struct object_entry **)vb;
231-
return a->tree_depth - b->tree_depth;
234+
const struct tree_islands_todo *todo_a = a;
235+
const struct tree_islands_todo *todo_b = b;
236+
237+
return todo_a->depth - todo_b->depth;
232238
}
233239

234240
void resolve_tree_islands(int progress, struct packing_data *to_pack)
235241
{
236242
struct progress *progress_state = NULL;
237-
struct object_entry **todo;
243+
struct tree_islands_todo *todo;
238244
int nr = 0;
239245
int i;
240246

@@ -250,16 +256,19 @@ void resolve_tree_islands(int progress, struct packing_data *to_pack)
250256
*/
251257
ALLOC_ARRAY(todo, to_pack->nr_objects);
252258
for (i = 0; i < to_pack->nr_objects; i++) {
253-
if (oe_type(&to_pack->objects[i]) == OBJ_TREE)
254-
todo[nr++] = &to_pack->objects[i];
259+
if (oe_type(&to_pack->objects[i]) == OBJ_TREE) {
260+
todo[nr].entry = &to_pack->objects[i];
261+
todo[nr].depth = oe_tree_depth(to_pack, &to_pack->objects[i]);
262+
nr++;
263+
}
255264
}
256-
QSORT(todo, nr, cmp_tree_depth);
265+
QSORT(todo, nr, tree_depth_compare);
257266

258267
if (progress)
259268
progress_state = start_progress(_("Propagating island marks"), nr);
260269

261270
for (i = 0; i < nr; i++) {
262-
struct object_entry *ent = todo[i];
271+
struct object_entry *ent = todo[i].entry;
263272
struct island_bitmap *root_marks;
264273
struct tree *tree;
265274
struct tree_desc desc;

pack-objects.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,
160160

161161
if (!pdata->in_pack_by_idx)
162162
REALLOC_ARRAY(pdata->in_pack, pdata->nr_alloc);
163+
164+
if (pdata->tree_depth)
165+
REALLOC_ARRAY(pdata->tree_depth, pdata->nr_alloc);
163166
}
164167

165168
new_entry = pdata->objects + pdata->nr_objects++;
@@ -175,5 +178,8 @@ struct object_entry *packlist_alloc(struct packing_data *pdata,
175178
if (pdata->in_pack)
176179
pdata->in_pack[pdata->nr_objects - 1] = NULL;
177180

181+
if (pdata->tree_depth)
182+
pdata->tree_depth[pdata->nr_objects - 1] = 0;
183+
178184
return new_entry;
179185
}

pack-objects.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ struct object_entry {
101101
unsigned no_try_delta:1;
102102
unsigned in_pack_type:TYPE_BITS; /* could be delta */
103103

104-
unsigned int tree_depth; /* should be repositioned for packing? */
105104
unsigned char layer;
106105

107106
unsigned preferred_base:1; /*
@@ -145,6 +144,9 @@ struct packing_data {
145144
struct packed_git **in_pack;
146145

147146
uintmax_t oe_size_limit;
147+
148+
/* delta islands */
149+
unsigned int *tree_depth;
148150
};
149151

150152
void prepare_packing_data(struct packing_data *pdata);
@@ -350,4 +352,21 @@ static inline void oe_set_delta_size(struct packing_data *pack,
350352
"where delta size is the same as entry size");
351353
}
352354

355+
static inline unsigned int oe_tree_depth(struct packing_data *pack,
356+
struct object_entry *e)
357+
{
358+
if (!pack->tree_depth)
359+
return 0;
360+
return pack->tree_depth[e - pack->objects];
361+
}
362+
363+
static inline void oe_set_tree_depth(struct packing_data *pack,
364+
struct object_entry *e,
365+
unsigned int tree_depth)
366+
{
367+
if (!pack->tree_depth)
368+
ALLOC_ARRAY(pack->tree_depth, pack->nr_objects);
369+
pack->tree_depth[e - pack->objects] = tree_depth;
370+
}
371+
353372
#endif

0 commit comments

Comments
 (0)