Re: [PATCH 1/9] string-list: add string_list_{pop, last} functions
- From
Ramsay Jones <ramsay@ramsayjones.plus.com>
- Date
- Sep 12, 2018, 02:24 UTC
- Message-ID
- <d6668ef0-2a9c-d591-fa4c-b8777576f334@ramsayjones.plus.com>
- In-Reply-To
- <20180911234951.14129-2-sbeller@google.com>
On 12/09/18 00:49, Stefan Beller wrote:
Show 22 quoted lines
> Add a few functions to allow a string-list to be used as a stack:
>
> - string_list_last() lets a caller peek the string_list_item at the
> end of the string list. The caller needs to be aware that it is
> borrowing a pointer, which can become invalid if/when the
> string_list is resized.
>
> - string_list_pop() removes the string_list_item at the end of
> the string list.
>
> - _pop usually has a friend _push. This role is taken by
> string_list_append already, as they are not symmetrical
> in our code base: _append returns the pointer, such that
> adding a util is easy, but _pop doesn't return such a pointer.
>
> You can use them in this pattern:
>
> while (list.nr) {
> struct string_list_item *item = string_list_last(&list);
>
> work_on(item);
> string_list_pop(&list);string_list_pop() takes a second int parameter (free_util).
ATB, Ramsay Jones