diff options
author | Patrick McDermott <pj@pehjota.net> | 2017-10-23 07:21:33 (EDT) |
---|---|---|
committer | Patrick McDermott <pj@pehjota.net> | 2017-10-23 07:21:33 (EDT) |
commit | 4d61838c33028595652f5ff54f76c10058b35e91 (patch) | |
tree | 53b18469e5b5855318f43601f4813f34550d9bb7 | |
parent | a5241c5fd7762b0f3d04491579390035df42f612 (diff) | |
download | marquee-4d61838c33028595652f5ff54f76c10058b35e91.zip marquee-4d61838c33028595652f5ff54f76c10058b35e91.tar.gz marquee-4d61838c33028595652f5ff54f76c10058b35e91.tar.bz2 |
MqTree: Reduce code in foreach*() static functions
-rw-r--r-- | src/tree.c | 32 |
1 files changed, 12 insertions, 20 deletions
@@ -151,32 +151,28 @@ static gboolean foreach(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data) { - gboolean ret; - - ret = MQ_TREE_CONTINUE; for (; node; node = node->next) { /* XXX: Warning: Does not skip root node */ - ret = cb(node, user_data); - if (ret == MQ_TREE_STOP) { - break; + if (cb(node, user_data) == MQ_TREE_STOP) { + return MQ_TREE_STOP; } if (node->first_child) { - ret = foreach(node->first_child, cb, user_data); - if (ret == MQ_TREE_STOP) { - break; + if (foreach(node->first_child, cb, user_data) == + MQ_TREE_STOP) { + return MQ_TREE_STOP; } } if (node->parent && node->parent->next) { - ret = foreach(node->parent->next, cb, user_data); - if (ret == MQ_TREE_STOP) { - break; + if (foreach(node->parent->next, cb, user_data) == + MQ_TREE_STOP) { + return MQ_TREE_STOP; } } } - return ret; + return MQ_TREE_CONTINUE; } void @@ -190,17 +186,13 @@ static gboolean foreach_child(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data) { - gboolean ret; - - ret = MQ_TREE_CONTINUE; for (node = node->first_child; node; node = node->next) { - ret = cb(node, user_data); - if (ret == MQ_TREE_STOP) { - break; + if (cb(node, user_data) == MQ_TREE_STOP) { + return MQ_TREE_STOP; } } - return ret; + return MQ_TREE_CONTINUE; } void |