From 4d61838c33028595652f5ff54f76c10058b35e91 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Mon, 23 Oct 2017 07:21:33 -0400 Subject: MqTree: Reduce code in foreach*() static functions --- diff --git a/src/tree.c b/src/tree.c index 9b2c22b..90a7af7 100644 --- a/src/tree.c +++ b/src/tree.c @@ -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 -- cgit v0.9.1