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

@ -31,8 +31,6 @@ static int send_command_not_found(struct command_base* cbase, struct hub_user* u
static int send_command_syntax_error(struct command_base* cbase, struct hub_user* user);
static int send_command_missing_arguments(struct command_base* cbase, struct hub_user* user, struct hub_command* cmd);
static void null_free(void* ptr) { }
struct command_base
{
struct hub_info* hub;
@ -424,7 +422,7 @@ static int command_whoip(struct command_base* cbase, struct hub_user* user, stru
ret = uman_get_user_by_addr(cbase->hub->users, users, arg->data.range);
if (!ret)
{
list_clear(users, &null_free);
list_clear(users, NULL);
list_destroy(users);
return command_status(cbase, user, cmd, cbuf_create_const("No users found."));
}
@ -439,7 +437,7 @@ static int command_whoip(struct command_base* cbase, struct hub_user* user, stru
cbuf_append(buf, "\n");
send_message(cbase, user, buf);
list_clear(users, &null_free);
list_clear(users, NULL);
list_destroy(users);
return 0;
}

View File

@ -109,11 +109,6 @@ void net_dns_destroy()
g_dns = NULL;
}
static void dummy_free(void* ptr)
{
}
void net_dns_process()
{
struct net_dns_result* result;
@ -148,7 +143,7 @@ void net_dns_process()
}
});
list_clear(g_dns->results, &dummy_free);
list_clear(g_dns->results, NULL);
uhub_mutex_unlock(&g_dns->mutex);
}

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);