aboutsummaryrefslogtreecommitdiffstats
path: root/common/list.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <RyanDwyer@users.noreply.github.com>2018-12-09 21:50:19 +1000
committerLibravatar GitHub <noreply@github.com>2018-12-09 21:50:19 +1000
commitb61a936c8060bc4ac4320a5f76fd98b5042e5e41 (patch)
tree279a5554686d6e862282c943bda50787b69711e1 /common/list.c
parentMerge pull request #3264 from ianyfan/resize-list (diff)
parentlist.c: rename free_flat_list to list_free_items_and_destroy (diff)
downloadsway-b61a936c8060bc4ac4320a5f76fd98b5042e5e41.tar.gz
sway-b61a936c8060bc4ac4320a5f76fd98b5042e5e41.tar.zst
sway-b61a936c8060bc4ac4320a5f76fd98b5042e5e41.zip
Merge pull request #3271 from ianyfan/list-cleanup
list.c: Remove list_foreach
Diffstat (limited to 'common/list.c')
-rw-r--r--common/list.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/common/list.c b/common/list.c
index 66cf133b..c3e2fe20 100644
--- a/common/list.c
+++ b/common/list.c
@@ -30,15 +30,6 @@ void list_free(list_t *list) {
30 free(list); 30 free(list);
31} 31}
32 32
33void list_foreach(list_t *list, void (*callback)(void *item)) {
34 if (list == NULL || callback == NULL) {
35 return;
36 }
37 for (int i = 0; i < list->length; i++) {
38 callback(list->items[i]);
39 }
40}
41
42void list_add(list_t *list, void *item) { 33void list_add(list_t *list, void *item) {
43 list_resize(list); 34 list_resize(list);
44 list->items[list->length++] = item; 35 list->items[list->length++] = item;
@@ -57,8 +48,7 @@ void list_del(list_t *list, int index) {
57} 48}
58 49
59void list_cat(list_t *list, list_t *source) { 50void list_cat(list_t *list, list_t *source) {
60 int i; 51 for (int i = 0; i < source->length; ++i) {
61 for (i = 0; i < source->length; ++i) {
62 list_add(list, source->items[i]); 52 list_add(list, source->items[i]);
63 } 53 }
64} 54}
@@ -156,3 +146,15 @@ void list_stable_sort(list_t *list, int compare(const void *a, const void *b)) {
156 list_inplace_sort(list, 0, list->length - 1, compare); 146 list_inplace_sort(list, 0, list->length - 1, compare);
157 } 147 }
158} 148}
149
150void list_free_items_and_destroy(list_t *list) {
151 if (!list) {
152 return;
153 }
154
155 for (int i = 0; i < list->length; ++i) {
156 free(list->items[i]);
157 }
158 list_free(list);
159}
160