Merge branch 'kn/bundle-dedup-optim'

Optimize the code to dedup references recorded in a bundle file.

* kn/bundle-dedup-optim:
  bundle: fix non-linear performance scaling with refs
  t6020: test for duplicate refnames in bundle creation
This commit is contained in:
Junio C Hamano
2025-04-23 13:58:50 -07:00
4 changed files with 61 additions and 41 deletions

View File

@@ -492,44 +492,11 @@ void object_array_clear(struct object_array *array)
array->nr = array->alloc = 0;
}
/*
* Return true if array already contains an entry.
*/
static int contains_object(struct object_array *array,
const struct object *item, const char *name)
{
unsigned nr = array->nr, i;
struct object_array_entry *object = array->objects;
for (i = 0; i < nr; i++, object++)
if (item == object->item && !strcmp(object->name, name))
return 1;
return 0;
}
void object_array_remove_duplicates(struct object_array *array)
{
unsigned nr = array->nr, src;
struct object_array_entry *objects = array->objects;
array->nr = 0;
for (src = 0; src < nr; src++) {
if (!contains_object(array, objects[src].item,
objects[src].name)) {
if (src != array->nr)
objects[array->nr] = objects[src];
array->nr++;
} else {
object_array_release_entry(&objects[src]);
}
}
}
void clear_object_flags(struct repository *repo, unsigned flags)
{
int i;
for (i=0; i < repo->parsed_objects->obj_hash_size; i++) {
for (i = 0; i < repo->parsed_objects->obj_hash_size; i++) {
struct object *obj = repo->parsed_objects->obj_hash[i];
if (obj)
obj->flags &= ~flags;