bisect: automatically sort sha1_array if needed when looking it up
This makes sha1_array easier to use, so later patches will be simpler. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
May 9, 2009 at 17:55 UTC
1da8c4fc2c85ed99e23d640bddedd8119150a1b8
1 file changed
+6
-2
bisect.c
+6
-2
@@ -13,6 +13,7 @@ struct sha1_array {
13
unsigned char (*sha1)[20];
14
int sha1_nr;
15
int sha1_alloc;
16
+ int sorted;
17
};
18
19
static struct sha1_array good_revs;
@@ -487,6 +488,8 @@ static int array_cmp(const void *a, const void *b)
488
static void sort_sha1_array(struct sha1_array *array)
489
{
490
qsort(array->sha1, array->sha1_nr, sizeof(*array->sha1), array_cmp);
491
+
492
+ array->sorted = 1;
493
}
494
495
static const unsigned char *sha1_access(size_t index, void *table)
@@ -498,6 +501,9 @@ static const unsigned char *sha1_access(size_t index, void *table)
501
static int lookup_sha1_array(struct sha1_array *array,
502
const unsigned char *sha1)
503
{
504
+ if (!array->sorted)
505
+ sort_sha1_array(array);
506
+
507
return sha1_pos(sha1, array->sha1, array->sha1_nr, sha1_access);
508
}
509
@@ -512,8 +518,6 @@ struct commit_list *filter_skipped(struct commit_list *list,
518
if (!skipped_revs.sha1_nr)
519
return list;
520
515
- sort_sha1_array(&skipped_revs);
516
-
521
while (list) {
522
struct commit_list *next = list->next;
523
list->next = NULL;