third_party/cairo/src/cairo-tor22-scan-converter.c
static struct edge *
merge_sorted_edges (struct edge *head_a, struct edge *head_b)
{
    struct edge *head, **next, *prev;
    int32_t x;

    prev = head_a->prev;
    next = &head;
    if (head_a->x.quo <= head_b->x.quo) {
	head = head_a;
    } else {
	head = head_b;
	head_b->prev = prev;
	goto start_with_b;
    }

    do {
	x = head_b->x.quo;
	while (head_a != NULL && head_a->x.quo <= x) {
	    prev = head_a;
	    next = &head_a->next;
	    head_a = head_a->next;
	}

	head_b->prev = prev;
	*next = head_b;
	if (head_a == NULL)
	    return head;

start_with_b:
	x = head_a->x.quo;
	while (head_b != NULL && head_b->x.quo <= x) {
	    prev = head_b;
	    next = &head_b->next;
	    head_b = head_b->next;
	}

	head_a->prev = prev;
	*next = head_a;
	if (head_b == NULL)
	    return head;
    } while (1);
}
/*
 * Merge two sorted edge lists.
 * Input:
 *  - head_a: The head of the first list.
 *  - head_b: The head of the second list; head_b cannot be NULL.
 * Output:
 * Returns the head of the merged list.
 *
 * Implementation notes:
 * To make it fast (in particular, to reduce to an insertion sort whenever
 * one of the two input lists only has a single element) we iterate through
 * a list until its head becomes greater than the head of the other list,
 * then we switch their roles. As soon as one of the two lists is empty, we
 * just attach the other one to the current list and exit.
 * Writes to memory are only needed to "switch" lists (as it also requires
 * attaching to the output list the list which we will be iterating next) and
 * to attach the last non-empty list.
 */
Merge two sorted edge lists.
Input:
- head_a: The head of the first list.
- head_b: The head of the second list; head_b cannot be NULL.
Output:
Returns the head of the merged list.

Implementation notes:
To make it fast (in particular, to reduce to an insertion sort whenever
one of the two input lists only has a single element) we iterate through
a list until its head becomes greater than the head of the other list,
then we switch their roles. As soon as one of the two lists is empty, we
just attach the other one to the current list and exit.
Writes to memory are only needed to "switch" lists (as it also requires
attaching to the output list the list which we will be iterating next) and
to attach the last non-empty list.
Merge two sorted edge lists . Input : - head_a : The head of the first list . - head_b : The head of the second list ; head_b cannot be NULL . Output : Returns the head of the merged list . Implementation notes : To make it fast ( in particular to reduce to an insertion sort whenever one of the two input lists only has a single element ) we iterate through a list until its head becomes greater than the head of the other list then we switch their roles . As soon as one of the two lists is empty we just attach the other one to the current list and exit . Writes to memory are only needed to " switch " lists ( as it also requires attaching to the output list the list which we will be iterating next ) and to attach the last non - empty list .
static struct edge *
merge_sorted_edges (struct edge *head_a, struct edge *head_b)
{
    struct edge *head, **next, *prev;
    int32_t x;
    prev = head_a->prev;
    next = &head;
    if (head_a->x.quo <= head_b->x.quo) {
	head = head_a;
    } else {
	head = head_b;
	head_b->prev = prev;
	goto start_with_b;
    }
    do {
	x = head_b->x.quo;
	while (head_a != NULL && head_a->x.quo <= x) {
	    prev = head_a;
	    next = &head_a->next;
	    head_a = head_a->next;
	}
	head_b->prev = prev;
	*next = head_b;
	if (head_a == NULL)
	    return head;
start_with_b:
	x = head_a->x.quo;
	while (head_b != NULL && head_b->x.quo <= x) {
	    prev = head_b;
	    next = &head_b->next;
	    head_b = head_b->next;
	}
	head_a->prev = prev;
	*next = head_a;
	if (head_b == NULL)
	    return head;
    } while (1);
}
static struct edge * merge_sorted_edges ( struct edge * head_a , struct edge * head_b ) { struct edge * head , * * next , * prev ; int32_t x ; prev = head_a -> prev ; next = & head ; if ( head_a -> x . quo <= head_b -> x . quo ) { head = head_a ; } else { head = head_b ; head_b -> prev = prev ; goto start_with_b ; } do { x = head_b -> x . quo ; while ( head_a != NULL && head_a -> x . quo <= x ) { prev = head_a ; next = & head_a -> next ; head_a = head_a -> next ; } head_b -> prev = prev ; * next = head_b ; if ( head_a == NULL ) return head ; start_with_b : x = head_a -> x . quo ; while ( head_b != NULL && head_b -> x . quo <= x ) { prev = head_b ; next = & head_b -> next ; head_b = head_b -> next ; } head_a -> prev = prev ; * next = head_a ; if ( head_b == NULL ) return head ; } while ( 1 ) ; }
Merge two sorted edge lists.
Merge two sorted edge lists .