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;
list_reset(list);
while(list->current!=NULL) list_del_element(list,list->current);
+ list->start=NULL;
return L_SUCCESS;
}
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