Simplify list_clear(), allow NULL as free() function pointer.

This makes it redundant to create a null_free() or dummy_free() function
that does nothing.
This commit is contained in:
Jan Vidar Krey
2014-08-05 13:08:46 +02:00
parent d33695435b
commit 1526d63403
4 changed files with 9 additions and 13 deletions

View File

@@ -40,11 +40,16 @@ void list_destroy(struct linked_list* list)
}
}
static void dummy_free(void* ptr)
{
}
void list_clear(struct linked_list* list, void (*free_handle)(void* ptr))
{
struct node* node = list->first;
struct node* tmp = NULL;
if (free_handle == NULL)
free_handle = &dummy_free;
while (node)
{
tmp = node->next;

View File

@@ -318,12 +318,10 @@ static struct rb_node* rb_it_set(struct rb_tree* tree, struct rb_node* n)
return n;
}
static void null_free(void* ptr) { }
struct rb_node* rb_tree_first(struct rb_tree* tree)
{
struct rb_node* n = tree->root;
list_clear(tree->iterator.stack, &null_free);
list_clear(tree->iterator.stack, NULL);
while (n->link[0])
{
push(tree, n);