Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simplify node addition.

  • Loading branch information...
commit 619f4291b1e70b3d41e04a5456597e9d6b43f00c 1 parent 8fbf689
@jof jof authored
Showing with 6 additions and 18 deletions.
  1. +6 −18 gateman.c
View
24 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
Please sign in to comment.
Something went wrong with that request. Please try again.