Merge pull request #3271 from ianyfan/list-cleanup

list.c: Remove list_foreach
This commit is contained in:
Ryan Dwyer 2018-12-09 21:50:19 +10:00 committed by GitHub
commit b61a936c80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 64 additions and 100 deletions

View file

@ -30,15 +30,6 @@ void list_free(list_t *list) {
free(list);
}
void list_foreach(list_t *list, void (*callback)(void *item)) {
if (list == NULL || callback == NULL) {
return;
}
for (int i = 0; i < list->length; i++) {
callback(list->items[i]);
}
}
void list_add(list_t *list, void *item) {
list_resize(list);
list->items[list->length++] = item;
@ -57,8 +48,7 @@ void list_del(list_t *list, int index) {
}
void list_cat(list_t *list, list_t *source) {
int i;
for (i = 0; i < source->length; ++i) {
for (int i = 0; i < source->length; ++i) {
list_add(list, source->items[i]);
}
}
@ -156,3 +146,15 @@ void list_stable_sort(list_t *list, int compare(const void *a, const void *b)) {
list_inplace_sort(list, 0, list->length - 1, compare);
}
}
void list_free_items_and_destroy(list_t *list) {
if (!list) {
return;
}
for (int i = 0; i < list->length; ++i) {
free(list->items[i]);
}
list_free(list);
}

View file

@ -45,10 +45,8 @@ struct loop *loop_create(void) {
}
void loop_destroy(struct loop *loop) {
list_foreach(loop->fd_events, free);
list_foreach(loop->timers, free);
list_free(loop->fd_events);
list_free(loop->timers);
list_free_items_and_destroy(loop->fd_events);
list_free_items_and_destroy(loop->timers);
free(loop->fds);
free(loop);
}

View file

@ -97,14 +97,6 @@ list_t *split_string(const char *str, const char *delims) {
return res;
}
void free_flat_list(list_t *list) {
int i;
for (i = 0; i < list->length; ++i) {
free(list->items[i]);
}
list_free(list);
}
char **split_args(const char *start, int *argc) {
*argc = 0;
int alloc = 2;