]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
network-list: Do not half list when popping the first element
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Nov 2020 14:42:26 +0000 (14:42 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Nov 2020 14:42:26 +0000 (14:42 +0000)
The list was unfortunately halved in size every time an element
was taken from it, which was great for performance, but shortened
the result substantially.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/network-list.c

index 2c4edb35882d3c32c1f5a791d04d60c6842c9cbe..f4a9d0593ee4208d76e9bff8065de6fe9e0615f6 100644 (file)
@@ -261,10 +261,13 @@ LOC_EXPORT struct loc_network* loc_network_list_pop_first(struct loc_network_lis
        struct loc_network* network = list->elements[0];
 
        // Move all elements to the top of the stack
-       for (unsigned int i = 0; i < --list->size; i++) {
+       for (unsigned int i = 0; i < list->size - 1; i++) {
                list->elements[i] = list->elements[i+1];
        }
 
+       // The list is shorter now
+       --list->size;
+
        DEBUG(list->ctx, "%p: Popping network %p from stack\n", list, network);
 
        return network;