pack-redundant.c: learn about index v2
Initially the conversion was made using nth_packed_object_sha1() which made this file completely index version agnostic. Unfortunately the overhead was quite significant so I went back to raw index walking but with selectable base and step values which brought back similar performances as the original. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Nicolas Pitre committed
Apr 9, 2007 at 01:06 UTC
8c681e07c91b544756e2631493ebc15abd1e8589
1 file changed
+27
-20
pack-redundant.c
+27
-20
@@ -247,16 +247,19 @@ static struct pack_list * pack_list_difference(const struct pack_list *A,
247
248
static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
249
{
250
- int p1_off, p2_off;
250
+ unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step;
251
const unsigned char *p1_base, *p2_base;
252
struct llist_item *p1_hint = NULL, *p2_hint = NULL;
253
254
- p1_off = p2_off = 256 * 4 + 4;
254
p1_base = p1->pack->index_data;
255
p2_base = p2->pack->index_data;
256
+ p1_base += 256 * 4 + ((p1->pack->index_version < 2) ? 4 : 8);
257
+ p2_base += 256 * 4 + ((p2->pack->index_version < 2) ? 4 : 8);
258
+ p1_step = (p1->pack->index_version < 2) ? 24 : 20;
259
+ p2_step = (p2->pack->index_version < 2) ? 24 : 20;
260
258
- while (p1_off <= p1->pack->index_size - 3 * 20 &&
259
- p2_off <= p2->pack->index_size - 3 * 20)
261
+ while (p1_off < p1->pack->num_objects * p1_step &&
262
+ p2_off < p2->pack->num_objects * p2_step)
263
{
264
int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
265
/* cmp ~ p1 - p2 */
@@ -265,14 +268,14 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
268
p1_base + p1_off, p1_hint);
269
p2_hint = llist_sorted_remove(p2->unique_objects,
270
p1_base + p1_off, p2_hint);
268
- p1_off+=24;
269
- p2_off+=24;
271
+ p1_off += p1_step;
272
+ p2_off += p2_step;
273
continue;
274
}
275
if (cmp < 0) { /* p1 has the object, p2 doesn't */
273
- p1_off+=24;
276
+ p1_off += p1_step;
277
} else { /* p2 has the object, p1 doesn't */
275
- p2_off+=24;
278
+ p2_off += p2_step;
279
}
280
}
281
}
@@ -352,28 +355,31 @@ static int is_superset(struct pack_list *pl, struct llist *list)
355
static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
356
{
357
size_t ret = 0;
355
- int p1_off, p2_off;
358
+ unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step;
359
const unsigned char *p1_base, *p2_base;
360
358
- p1_off = p2_off = 256 * 4 + 4;
361
p1_base = p1->index_data;
362
p2_base = p2->index_data;
363
+ p1_base += 256 * 4 + ((p1->index_version < 2) ? 4 : 8);
364
+ p2_base += 256 * 4 + ((p2->index_version < 2) ? 4 : 8);
365
+ p1_step = (p1->index_version < 2) ? 24 : 20;
366
+ p2_step = (p2->index_version < 2) ? 24 : 20;
367
362
- while (p1_off <= p1->index_size - 3 * 20 &&
363
- p2_off <= p2->index_size - 3 * 20)
368
+ while (p1_off < p1->num_objects * p1_step &&
369
+ p2_off < p2->num_objects * p2_step)
370
{
371
int cmp = hashcmp(p1_base + p1_off, p2_base + p2_off);
372
/* cmp ~ p1 - p2 */
373
if (cmp == 0) {
374
ret++;
369
- p1_off+=24;
370
- p2_off+=24;
375
+ p1_off += p1_step;
376
+ p2_off += p2_step;
377
continue;
378
}
379
if (cmp < 0) { /* p1 has the object, p2 doesn't */
374
- p1_off+=24;
380
+ p1_off += p1_step;
381
} else { /* p2 has the object, p1 doesn't */
376
- p2_off+=24;
382
+ p2_off += p2_step;
383
}
384
}
385
return ret;
@@ -535,7 +541,7 @@ static void scan_alt_odb_packs(void)
541
static struct pack_list * add_pack(struct packed_git *p)
542
{
543
struct pack_list l;
538
- size_t off;
544
+ unsigned long off = 0, step;
545
const unsigned char *base;
546
547
if (!p->pack_local && !(alt_odb || verbose))
@@ -544,11 +550,12 @@ static struct pack_list * add_pack(struct packed_git *p)
550
l.pack = p;
551
llist_init(&l.all_objects);
552
547
- off = 256 * 4 + 4;
553
base = p->index_data;
549
- while (off <= p->index_size - 3 * 20) {
554
+ base += 256 * 4 + ((p->index_version < 2) ? 4 : 8);
555
+ step = (p->index_version < 2) ? 24 : 20;
556
+ while (off < p->num_objects * step) {
557
llist_insert_back(l.all_objects, base + off);
551
- off += 24;
558
+ off += step;
559
}
560
/* this list will be pruned in cmp_two_packs later */
561
l.unique_objects = llist_copy(l.all_objects);