]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
as-list: Grow faster to avoid too many re-allocations
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 9 Mar 2022 10:15:49 +0000 (10:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 9 Mar 2022 10:15:49 +0000 (10:15 +0000)
When we add a large number of ASes to the list, we will constantly
re-allocate the whole list because we are only growing it by 64 entries
at a time.

This patch changes that we will double the list in size every time we
run out of space and we will start with 1024 elements.

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

index 820357c4ef2fd9ecc42144238ab52421e950828b..26fe9fb6cbd65374e56e2930a3c2fa829ee3ab6b 100644 (file)
@@ -31,7 +31,11 @@ struct loc_as_list {
        size_t size;
 };
 
-static int loc_as_list_grow(struct loc_as_list* list, size_t size) {
+static int loc_as_list_grow(struct loc_as_list* list) {
+       size_t size = list->elements_size * 2;
+       if (size < 1024)
+               size = 1024;
+
        DEBUG(list->ctx, "Growing AS list %p by %zu to %zu\n",
                list, size, list->elements_size + size);
 
@@ -124,7 +128,7 @@ LOC_EXPORT int loc_as_list_append(
 
        // Check if we have space left
        if (list->size >= list->elements_size) {
-               int r = loc_as_list_grow(list, 64);
+               int r = loc_as_list_grow(list);
                if (r)
                        return r;
        }