aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2018-12-08 22:52:29 +0000
committerLibravatar Ian Fan <ianfan0@gmail.com>2018-12-09 00:37:50 +0000
commit19e831ed3da2aba75d56e46c57967bcc60442d57 (patch)
treeedaa5855087f9d6f257c5c6dcd5eda0c4cc55b02 /common
parentMerge pull request #3260 from RedSoxFan/split-flatten (diff)
downloadsway-19e831ed3da2aba75d56e46c57967bcc60442d57.tar.gz
sway-19e831ed3da2aba75d56e46c57967bcc60442d57.tar.zst
sway-19e831ed3da2aba75d56e46c57967bcc60442d57.zip
list.c: Remove list_foreach
Most occurrences have been replaced by `free_flat_list` which has been moved from stringop.c to list.c. The rest have been replaced by for loops.
Diffstat (limited to 'common')
-rw-r--r--common/list.c21
-rw-r--r--common/loop.c6
-rw-r--r--common/stringop.c8
3 files changed, 14 insertions, 21 deletions
diff --git a/common/list.c b/common/list.c
index ee268c9a..a0b42512 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;
@@ -156,3 +147,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); 147 list_inplace_sort(list, 0, list->length - 1, compare);
157 } 148 }
158} 149}
150
151void free_flat_list(list_t *list) {
152 if (!list) {
153 return;
154 }
155
156 for (int i = 0; i < list->length; ++i) {
157 free(list->items[i]);
158 }
159 list_free(list);
160}
161
diff --git a/common/loop.c b/common/loop.c
index 82b80017..ad2b4a64 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 free_flat_list(loop->fd_events);
49 list_foreach(loop->timers, free); 49 free_flat_list(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;