@matheusbsbs / matheus-bagliano / commits / b904166ccb
Fork 0

pack-objects: reverse the delta search sort list

It is currently sorted and then walked backward. Not only this doesn't feel natural for my poor brain, but it would make the next patch less obvious as well. So reverse the sort order, and reverse the list walking direction, which effectively produce the exact same end result as before. Also bring the relevant comment nearer the actual code and adjust it accordingly, with minor additional clarifications. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nicolas Pitre committed Dec 8, 2007 at 00:00 UTC b904166ccb67d80491fad9d4f5ec42d241975f37
1 file changed +21 -20
builtin-pack-objects.c
+21 -20
@@ -1245,28 +1245,37 @@ static void get_object_details(void)
1245 free(sorted_by_offset);
1246 }
1247
1248 +/*
1249 + * We search for deltas in a list sorted by type, by filename hash, and then
1250 + * by size, so that we see progressively smaller and smaller files.
1251 + * That's because we prefer deltas to be from the bigger file
1252 + * to the smaller -- deletes are potentially cheaper, but perhaps
1253 + * more importantly, the bigger file is likely the more recent
1254 + * one. The deepest deltas are therefore the oldest objects which are
1255 + * less susceptible to be accessed often.
1256 + */
1257 static int type_size_sort(const void *_a, const void *_b)
1258 {
1259 const struct object_entry *a = *(struct object_entry **)_a;
1260 const struct object_entry *b = *(struct object_entry **)_b;
1261
1253 - if (a->type < b->type)
1254 - return -1;
1262 if (a->type > b->type)
1256 - return 1;
1257 - if (a->hash < b->hash)
1263 return -1;
1259 - if (a->hash > b->hash)
1264 + if (a->type < b->type)
1265 return 1;
1261 - if (a->preferred_base < b->preferred_base)
1266 + if (a->hash > b->hash)
1267 return -1;
1263 - if (a->preferred_base > b->preferred_base)
1268 + if (a->hash < b->hash)
1269 return 1;
1265 - if (a->size < b->size)
1270 + if (a->preferred_base > b->preferred_base)
1271 return -1;
1272 + if (a->preferred_base < b->preferred_base)
1273 + return 1;
1274 if (a->size > b->size)
1275 + return -1;
1276 + if (a->size < b->size)
1277 return 1;
1269 - return a > b ? -1 : (a < b); /* newest last */
1278 + return a < b ? -1 : (a > b); /* newest first */
1279 }
1280
1281 struct unpacked {
@@ -1317,14 +1326,6 @@ static pthread_mutex_t progress_mutex = PTHREAD_MUTEX_INITIALIZER;
1326
1327 #endif
1328
1320 -/*
1321 - * We search for deltas _backwards_ in a list sorted by type and
1322 - * by size, so that we see progressively smaller and smaller files.
1323 - * That's because we prefer deltas to be from the bigger file
1324 - * to the smaller - deletes are potentially cheaper, but perhaps
1325 - * more importantly, the bigger file is likely the more recent
1326 - * one.
1327 - */
1329 static int try_delta(struct unpacked *trg, struct unpacked *src,
1330 unsigned max_depth, unsigned long *mem_usage)
1331 {
@@ -1481,7 +1482,7 @@ static unsigned long free_unpacked(struct unpacked *n)
1482 static void find_deltas(struct object_entry **list, unsigned list_size,
1483 int window, int depth, unsigned *processed)
1484 {
1484 - uint32_t i = list_size, idx = 0, count = 0;
1485 + uint32_t i = 0, idx = 0, count = 0;
1486 unsigned int array_size = window * sizeof(struct unpacked);
1487 struct unpacked *array;
1488 unsigned long mem_usage = 0;
@@ -1490,7 +1491,7 @@ static void find_deltas(struct object_entry **list, unsigned list_size,
1491 memset(array, 0, array_size);
1492
1493 do {
1493 - struct object_entry *entry = list[--i];
1494 + struct object_entry *entry = list[i++];
1495 struct unpacked *n = array + idx;
1496 int j, max_depth, best_base = -1;
1497
@@ -1575,7 +1576,7 @@ static void find_deltas(struct object_entry **list, unsigned list_size,
1576 count++;
1577 if (idx >= window)
1578 idx = 0;
1578 - } while (i > 0);
1579 + } while (i < list_size);
1580
1581 for (i = 0; i < window; ++i) {
1582 free_delta_index(array[i].index);