From: hackbard Date: Fri, 15 Dec 2006 01:16:37 +0000 (+0000) Subject: added fast(er) list to be included (just in header) + small bug fix X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=my-code%2Fapi.git added fast(er) list to be included (just in header) + small bug fix --- diff --git a/list/list.c b/list/list.c index 79d53f7..79b41d2 100644 --- a/list/list.c +++ b/list/list.c @@ -28,7 +28,8 @@ int list_shutdown(t_list *list) { int list_next(t_list *list) { - if(list->current->next==NULL) return L_NO_NEXT_ELEMENT; + if(list->current->next==NULL) + return L_NO_NEXT_ELEMENT; list->current=list->current->next; @@ -75,6 +76,7 @@ int list_destroy(t_list *list) { list_reset(list); while(list->current!=NULL) list_del_element(list,list->current); + list->start=NULL; return L_SUCCESS; } diff --git a/list/list.h b/list/list.h index 4302d32..8f5328a 100644 --- a/list/list.h +++ b/list/list.h @@ -44,4 +44,84 @@ int list_add_immediate(t_list *list,void *data,int data_len); int list_add_element(t_list *list,void *data,int data_len); int list_count(t_list *list); +/* + * fast linked list routines to be inlined + */ + +/* prototypes */ + +static inline int list_init_f(t_list *list) __attribute__((always_inline)); +static inline int list_reset_f(t_list *list) __attribute__((always_inline)); +static inline int list_destroy_f(t_list *list) __attribute__((always_inline)); +static inline int list_add_immediate_f(t_list *list,void *ptr) __attribute__((always_inline)); +static inline int list_next_f(t_list *list) __attribute__((always_inline)); + +/* definitions */ + +static inline int list_init_f(t_list *list) { + + list->start=NULL; + list->current=list->start; + + return L_SUCCESS; +} + +static inline int list_reset_f(t_list *list) { + + list->current=list->start; + + return L_SUCCESS; +} + +static inline int list_destroy_f(t_list *list) { + + t_list_element *this; + + /* destroying the list from the very beginning */ + list->current=list->start; + + while(list->current!=NULL) { + this=list->current; + list->current=this->next; + free(this); + } + + list->start=NULL; + + return L_SUCCESS; +} + +static inline int list_add_immediate_f(t_list *list,void *ptr) { + + /* first element? */ + if(list->start==NULL) { + list->start=malloc(sizeof(t_list_element)); + list->start->data=ptr; + list->start->next=NULL; + list->start->prev=NULL; + list->current=list->start; + + return L_SUCCESS; + } + + list->current->next=malloc(sizeof(t_list_element)); + list->current->next->prev=list->current; + list->current->next->next=NULL; + list->current->next->data=ptr; + list->current=list->current->next; + + return L_SUCCESS; +} + +static inline int list_next_f(t_list *list) { + + if(list->current->next==NULL) + return L_NO_NEXT_ELEMENT; + + list->current=list->current->next; + + return L_SUCCESS; +} + + #endif