aboutsummaryrefslogtreecommitdiffstats
path: root/common
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
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')
-rw-r--r--common/list.c24
-rw-r--r--common/loop.c6
-rw-r--r--common/stringop.c8
3 files changed, 15 insertions, 23 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
diff --git a/common/loop.c b/common/loop.c
index 82b80017..295f3a30 100644
--- a/common/loop.c
+++ b/common/loop.c
@@ -45,10 +45,8 @@ struct loop *loop_create(void) {
45} 45}
46 46
47void loop_destroy(struct loop *loop) { 47void loop_destroy(struct loop *loop) {
48 list_foreach(loop->fd_events, free); 48 list_free_items_and_destroy(loop->fd_events);
49 list_foreach(loop->timers, free); 49 list_free_items_and_destroy(loop->timers);
50 list_free(loop->fd_events);
51 list_free(loop->timers);
52 free(loop->fds); 50 free(loop->fds);
53 free(loop); 51 free(loop);
54} 52}
diff --git a/common/stringop.c b/common/stringop.c
index df016e9d..4b8c9a38 100644
--- a/common/stringop.c
+++ b/common/stringop.c
@@ -97,14 +97,6 @@ list_t *split_string(const char *str, const char *delims) {
97 return res; 97 return res;
98} 98}
99 99
100void free_flat_list(list_t *list) {
101 int i;
102 for (i = 0; i < list->length; ++i) {
103 free(list->items[i]);
104 }
105 list_free(list);
106}
107
108char **split_args(const char *start, int *argc) { 100char **split_args(const char *start, int *argc) {
109 *argc = 0; 101 *argc = 0;
110 int alloc = 2; 102 int alloc = 2;