lkml.org 
[lkml]   [2023]   [Oct]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [RFC PATCH 1/2] add list_for_each_entry_del()
Date
From: Miklos Szeredi
> Sent: 20 October 2023 11:29
>
> Add a new list iteration macro that always takes the first element of the
> list and removes it, until the list is empty.
...
> +/**
> + * list_for_each_entry_del - iterate list and remove elements
> + * @pos: the type * to use as a loop cursor.
> + * @head: the head for your list.
> + * @member: the name of the list_head within the struct.
> + *
> + * Delete first element from list before the iteration. Iterate until
> + * the list is empty.
> + */
> +#define list_for_each_entry_del(pos, head, member) \
> + while (!list_empty(head) && \
> + ({ pos = list_first_entry(head, typeof(*(pos)), member);\
> + list_del(&(pos)->member); 1; }))

That pattern is actually pretty obvious.
Add another wrapper and people end up having to read the
header to find out what it does.

I can't help feeling that if you look inside list_empty(),
list_first_entry() and list_del() there is a lot of
replicated code and tests.

Adding a list_del_first() function that returns the deleted
item or NULL to optimise it might make more sense.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

\
 
 \ /
  Last update: 2023-10-21 12:01    [W:0.053 / U:1.944 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site