libpkgconf: iter: track list lengths

feature/tap-sh
William Pitcock 2016-12-30 09:57:01 -06:00
parent b0f8eab754
commit 135da1440c
1 changed files with 8 additions and 1 deletions

View File

@ -25,9 +25,10 @@ struct pkgconf_node_ {
typedef struct { typedef struct {
pkgconf_node_t *head, *tail; pkgconf_node_t *head, *tail;
size_t length;
} pkgconf_list_t; } pkgconf_list_t;
#define PKGCONF_LIST_INITIALIZER { NULL, NULL } #define PKGCONF_LIST_INITIALIZER { NULL, NULL, 0 }
static inline void static inline void
pkgconf_node_insert(pkgconf_node_t *node, void *data, pkgconf_list_t *list) pkgconf_node_insert(pkgconf_node_t *node, void *data, pkgconf_list_t *list)
@ -40,6 +41,7 @@ pkgconf_node_insert(pkgconf_node_t *node, void *data, pkgconf_list_t *list)
{ {
list->head = node; list->head = node;
list->tail = node; list->tail = node;
list->length = 1;
return; return;
} }
@ -49,6 +51,7 @@ pkgconf_node_insert(pkgconf_node_t *node, void *data, pkgconf_list_t *list)
tnode->prev = node; tnode->prev = node;
list->head = node; list->head = node;
list->length++;
} }
static inline void static inline void
@ -62,6 +65,7 @@ pkgconf_node_insert_tail(pkgconf_node_t *node, void *data, pkgconf_list_t *list)
{ {
list->head = node; list->head = node;
list->tail = node; list->tail = node;
list->length = 1;
return; return;
} }
@ -71,11 +75,14 @@ pkgconf_node_insert_tail(pkgconf_node_t *node, void *data, pkgconf_list_t *list)
tnode->next = node; tnode->next = node;
list->tail = node; list->tail = node;
list->length++;
} }
static inline void static inline void
pkgconf_node_delete(pkgconf_node_t *node, pkgconf_list_t *list) pkgconf_node_delete(pkgconf_node_t *node, pkgconf_list_t *list)
{ {
list->length--;
if (node->prev == NULL) if (node->prev == NULL)
list->head = node->next; list->head = node->next;
else else