libcgi
libcgi copied to clipboard
slist_add() doing more than it needs to
In "list.c", slist_add() could be greatly simplified if we ignore the order - appending. This is how the code could look if we prepend to the list instead:
void slist_add(formvars *item, formvars **list)
{
item->next = *list;
*list = item;
}
Yes, this would speed up the insertion of new items, but I guess not much. The current code uses a pointer to the last element of the list. The test for *list or *start to be a NULL pointer can not be dropped, so you save only one assignment. The current code is basically this:
(*last)->next = item;
item->next = NULL;
*last = item;
Are you suffering from performance issues? I doubt this would be noticeable, not even with large numbers of additions, which we don't have in practice anyway?