From 619f4291b1e70b3d41e04a5456597e9d6b43f00c Mon Sep 17 00:00:00 2001 From: Jonathan Lassoff Date: Thu, 15 Dec 2011 09:31:20 -0800 Subject: [PATCH] Simplify node addition. --- gateman.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/gateman.c b/gateman.c index a8ba121..ec258b6 100644 --- a/gateman.c +++ b/gateman.c @@ -100,24 +100,12 @@ struct subscription_node* make_subscription_node(struct subscription* subscripti } void insert_subscription_node(struct subscription_node* node) { - // FIXME It would be more efficient to shift in new subscriptions to the head - // (order doesn't really matter), rather than walking the list each time - struct subscription_node* n; - if (subscriptions_head == NULL) { // A new, empty list - node->previous = NULL; - node->next = NULL; - subscriptions_head = node; - } else { - // Walk the list, find the end, re-point pointers there - for(n = subscriptions_head; n != NULL; n = n->next) { - if(n->next == NULL) { // We're at the end of the list. - node->previous = n; - node->next = NULL; - n->next = node; - break; - } - } - } + // Initialize the node's pointers. + node->next = NULL; + node->previous = NULL; + // Push the new node onto the head of the list. + node->next = subscriptions_head; + subscriptions_head = node; } // Remove a node from the list by re-pointing it's neighbors, or the head