From: Adrian Ratiu Date: Sun, 01 Mar 2026 18:44:52 GMT Subject: [PATCH v3 04/12] string-list: add unsorted_string_list_remove() Message-ID: <20260301184500.1488433-5-adrian.ratiu@collabora.com> In-Reply-To: <20260301184500.1488433-1-adrian.ratiu@collabora.com> Add a convenience wrapper that combines unsorted_string_list_lookup() with unsorted_string_list_delete_item(), removing the first item matching a given string. This is a companion to the existing unsorted string_list helpers and will be used in the next commits. Suggested-by: Patrick Steinhardt Signed-off-by: Adrian Ratiu --- string-list.c | 9 +++++++++ string-list.h | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/string-list.c b/string-list.c index fffa2ad4b6..d260b873c8 100644 --- a/string-list.c +++ b/string-list.c @@ -281,6 +281,15 @@ void unsorted_string_list_delete_item(struct string_list *list, int i, int free_ list->nr--; } +void unsorted_string_list_remove(struct string_list *list, const char *str, + int free_util) +{ + struct string_list_item *item = unsorted_string_list_lookup(list, str); + if (item) + unsorted_string_list_delete_item(list, item - list->items, + free_util); +} + /* * append a substring [p..end] to list; return number of things it * appended to the list. diff --git a/string-list.h b/string-list.h index 3ad862a187..b86ee7c099 100644 --- a/string-list.h +++ b/string-list.h @@ -265,6 +265,14 @@ struct string_list_item *unsorted_string_list_lookup(struct string_list *list, */ void unsorted_string_list_delete_item(struct string_list *list, int i, int free_util); +/** + * Remove the first item matching `str` from an unsorted string_list. + * No-op if `str` is not found. If `free_util` is non-zero, the `util` + * pointer of the removed item is freed before deletion. + */ +void unsorted_string_list_remove(struct string_list *list, const char *str, + int free_util); + /** * Split string into substrings on characters in `delim` and append the * substrings to `list`. The input string is not modified. -- 2.52.0.732.gb351b5166d.dirty