[lvm-devel] [PATCH 01/22] Add dm_list_splice() for list join.
Alasdair G Kergon
agk at redhat.com
Mon Apr 26 13:15:13 UTC 2010
On Mon, Apr 12, 2010 at 05:21:29PM +0200, Zdenek Kabelac wrote:
> Introduce dm_list_splice to join two lists.
OK, but do please retain the style and conventions of the existing functions.
> +void dm_list_splice(struct dm_list *list, struct dm_list *head)
Based on existing conventions, the code appears to implement:
dm_list_splice_h(struct dm_list *head, struct dm_list *list)
Try the following (untested) instead:
/*
* Join two lists together.
* This moves all the elements of the list 'head1' to the end of the list
* 'head', leaving 'head1' empty.
*/
void dm_list_splice(struct dm_list *head, struct dm_list *head1)
{
assert(head->n);
assert(head1->n);
head1->p->n = head;
head1->n->p = head->p;
head->p->n = head1->n;
head->p = head1->p;
dm_list_init(head1);
}
Of if you genuinely require the _h version (i.e. the elements are ordered and
you can't choose to retain 'head1' for the combined list instead of 'head.)
/*
* Join two lists together.
* This moves all the elements of the list 'head1' to the front of the list
* 'head', leaving 'head1' empty.
*/
void dm_list_splice_h(struct dm_list *head, struct dm_list *head1)
{
assert(head->n);
assert(head1->n);
head1->n->p = head;
head1->p->n = head->n;
head->n->p = head1->p;
head->n = head1->n;
dm_list_init(head1);
}
Alasdair
More information about the lvm-devel
mailing list