libcgi icon indicating copy to clipboard operation
libcgi copied to clipboard

slist_add() doing more than it needs to

Open DFrostByte opened this issue 10 years ago • 1 comments

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

DFrostByte avatar Apr 04 '15 16:04 DFrostByte

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?

LeSpocky avatar May 10 '16 11:05 LeSpocky