string-list: Add API to remove an item from an unsorted list
Teach the string-list API how to remove an entry in O(1) runtime by moving the last entry to the vacated spot. As such, the routine works only for unsorted lists. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
aacb82de3f
commit
86d4b528d8
@ -185,3 +185,12 @@ int unsorted_string_list_has_string(struct string_list *list,
|
||||
return unsorted_string_list_lookup(list, string) != NULL;
|
||||
}
|
||||
|
||||
void unsorted_string_list_delete_item(struct string_list *list, int i, int free_util)
|
||||
{
|
||||
if (list->strdup_strings)
|
||||
free(list->items[i].string);
|
||||
if (free_util)
|
||||
free(list->items[i].util);
|
||||
list->items[i] = list->items[list->nr-1];
|
||||
list->nr--;
|
||||
}
|
||||
|
Reference in New Issue
Block a user