@matheusbsbs / matheus-bagliano / commits / 9668cf59a8
Fork 0

pack-objects: clean up list sorting

Get rid of sort_comparator() as it impose a run time double indirect function call for little compile time type checking gain. Also get rid of create_sorted_list() as it only has one user which would as well be just fine doing its sorting locally. Eventually the list of deltifiable objects might be shorter than the whole object list. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nicolas Pitre committed Apr 16, 2007 at 12:29 UTC 9668cf59a83d1aa881036818abf29cc2ea9e291b
1 file changed +22 -31
builtin-pack-objects.c
+22 -31
@@ -66,7 +66,7 @@ static int local;
66 static int incremental;
67 static int allow_ofs_delta;
68
69 -static struct object_entry **sorted_by_sha, **sorted_by_type;
69 +static struct object_entry **sorted_by_sha;
70 static struct object_entry *objects;
71 static uint32_t nr_objects, nr_alloc, nr_result;
72 static const char *base_name;
@@ -1181,31 +1181,10 @@ static void get_object_details(void)
1181 check_object(entry);
1182 }
1183
1184 -typedef int (*entry_sort_t)(const struct object_entry *, const struct object_entry *);
1185 -
1186 -static entry_sort_t current_sort;
1187 -
1188 -static int sort_comparator(const void *_a, const void *_b)
1189 -{
1190 - struct object_entry *a = *(struct object_entry **)_a;
1191 - struct object_entry *b = *(struct object_entry **)_b;
1192 - return current_sort(a,b);
1193 -}
1194 -
1195 -static struct object_entry **create_sorted_list(entry_sort_t sort)
1196 -{
1197 - struct object_entry **list = xmalloc(nr_objects * sizeof(struct object_entry *));
1198 - uint32_t i;
1199 -
1200 - for (i = 0; i < nr_objects; i++)
1201 - list[i] = objects + i;
1202 - current_sort = sort;
1203 - qsort(list, nr_objects, sizeof(struct object_entry *), sort_comparator);
1204 - return list;
1205 -}
1206 -
1207 -static int sha1_sort(const struct object_entry *a, const struct object_entry *b)
1184 +static int sha1_sort(const void *_a, const void *_b)
1185 {
1186 + const struct object_entry *a = *(struct object_entry **)_a;
1187 + const struct object_entry *b = *(struct object_entry **)_b;
1188 return hashcmp(a->sha1, b->sha1);
1189 }
1190
@@ -1222,13 +1201,15 @@ static struct object_entry **create_final_object_list(void)
1201 if (!objects[i].preferred_base)
1202 list[j++] = objects + i;
1203 }
1225 - current_sort = sha1_sort;
1226 - qsort(list, nr_result, sizeof(struct object_entry *), sort_comparator);
1204 + qsort(list, nr_result, sizeof(struct object_entry *), sha1_sort);
1205 return list;
1206 }
1207
1230 -static int type_size_sort(const struct object_entry *a, const struct object_entry *b)
1208 +static int type_size_sort(const void *_a, const void *_b)
1209 {
1210 + const struct object_entry *a = *(struct object_entry **)_a;
1211 + const struct object_entry *b = *(struct object_entry **)_b;
1212 +
1213 if (a->type < b->type)
1214 return -1;
1215 if (a->type > b->type)
@@ -1448,10 +1429,20 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1429
1430 static void prepare_pack(int window, int depth)
1431 {
1432 + struct object_entry **delta_list;
1433 + uint32_t i;
1434 +
1435 get_object_details();
1452 - sorted_by_type = create_sorted_list(type_size_sort);
1453 - if (window && depth)
1454 - find_deltas(sorted_by_type, window+1, depth);
1436 +
1437 + if (!window || !depth)
1438 + return;
1439 +
1440 + delta_list = xmalloc(nr_objects * sizeof(*delta_list));
1441 + for (i = 0; i < nr_objects; i++)
1442 + delta_list[i] = objects + i;
1443 + qsort(delta_list, nr_objects, sizeof(*delta_list), type_size_sort);
1444 + find_deltas(delta_list, window+1, depth);
1445 + free(delta_list);
1446 }
1447
1448 static int reuse_cached_pack(unsigned char *sha1)