[hipl-dev] Re: [Merge] lp:~hipl-core/hipl/libhip into lp:hipl

  • From: Christof Mroz <christof.mroz@xxxxxxxxxxxxxx>
  • To: hipl-dev@xxxxxxxxxxxxx
  • Date: Tue, 21 Feb 2012 14:41:48 +0100

On 20.02.2012 21:03, Christof Mroz wrote:
struct hip_ll_node **storage = &linkedlist->head;
struct hip_ll_node  *node    =  linkedlist->head;

while(node) {
    if(node->ptr == ptr) {
        *storage = node->next;
        free(node);
        node = *storage;

        linkedlist->elementcount -= 1;
        // could return here for micro optimization
    } else {
        storage = &node->next;
        node    =  node->next;
    }
}

Just realized this can be compacted some more:

struct hip_ll_node **storage = &linkedlist->head;

while(*storage) {
    struct hip_ll_node *const node = *storage;

    if(node->ptr == ptr) {
        linkedlist->elementcount -= 1;
        *storage                  = node->next;

        free(node);
        // could return here for micro optimization
    } else {
        storage = &node->next;
    }
}

Other related posts: