]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add hint for edit list size
authorAlan T. DeKok <aland@freeradius.org>
Sat, 13 Nov 2021 13:50:34 +0000 (08:50 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 13 Nov 2021 13:50:34 +0000 (08:50 -0500)
so that all of the edits can (generally) live in a contiguous
region of memory, and then be freed all at once.

src/lib/util/edit.c
src/lib/util/edit.h
src/lib/util/edit_tests.c

index 324e8504e184420c2f8f258a09d88cdc6893e407..4dbda60ff2c6a80d2bd2d08869651e4d20a941f6 100644 (file)
@@ -26,6 +26,7 @@
 RCSID("$Id$")
 
 #include <freeradius-devel/util/value.h>
+#include <freeradius-devel/util/talloc.h>
 #include "edit.h"
 
 typedef enum {
@@ -459,11 +460,11 @@ static int _edit_list_destructor(fr_edit_list_t *el)
        return 0;
 }
 
-fr_edit_list_t *fr_edit_list_alloc(TALLOC_CTX *ctx)
+fr_edit_list_t *fr_edit_list_alloc(TALLOC_CTX *ctx, int hint)
 {
        fr_edit_list_t *el;
 
-       el = talloc_zero(ctx, fr_edit_list_t);
+       el = talloc_zero_pooled_object(ctx, fr_edit_list_t, hint, hint * sizeof(fr_edit_t));
        if (!el) return NULL;
 
        fr_dlist_init(&el->list, fr_edit_t, entry);
index d20d470168dcc3448cb623976fb0069f9ac29fe3..7246fb45e93b1e431680813906ad3a5c8a6d5876 100644 (file)
@@ -33,7 +33,7 @@ extern "C" {
 
 typedef struct fr_edit_list_s fr_edit_list_t;
 
-fr_edit_list_t *fr_edit_list_alloc(TALLOC_CTX *ctx);
+fr_edit_list_t *fr_edit_list_alloc(TALLOC_CTX *ctx, int hint);
 
 void fr_edit_list_abort(fr_edit_list_t *el);
 
index 95c7ff3a7df1b2b1ec7b35bb77068f3b4807e999..f16d827b0cb7463bf7ad2893c64c3a12aab8fe64 100644 (file)
@@ -129,7 +129,7 @@ static void test_pair_delete_head(void)
 
        vp = fr_pair_list_head(&local_pairs);
 
-       el = fr_edit_list_alloc(NULL);
+       el = fr_edit_list_alloc(NULL, 5);
        fr_assert(el != NULL);
 
        rcode = fr_edit_list_delete(el, &local_pairs, vp);
@@ -162,7 +162,7 @@ static void test_pair_delete_head_abort(void)
 
        vp = fr_pair_list_head(&local_pairs);
 
-       el = fr_edit_list_alloc(NULL);
+       el = fr_edit_list_alloc(NULL, 5);
        fr_assert(el != NULL);
 
        rcode = fr_edit_list_delete(el, &local_pairs, vp);
@@ -196,7 +196,7 @@ static void test_pair_delete_middle(void)
        vp = fr_pair_list_next(&local_pairs, vp);
        fr_assert(vp != NULL);
 
-       el = fr_edit_list_alloc(NULL);
+       el = fr_edit_list_alloc(NULL, 5);
        fr_assert(el != NULL);
 
        rcode = fr_edit_list_delete(el, &local_pairs, vp);
@@ -235,7 +235,7 @@ static void test_pair_delete_middle_abort(void)
        fr_assert(middle != NULL);
        TEST_CHECK(middle->da == fr_dict_attr_test_octets);
 
-       el = fr_edit_list_alloc(NULL);
+       el = fr_edit_list_alloc(NULL, 5);
        fr_assert(el != NULL);
 
        rcode = fr_edit_list_delete(el, &local_pairs, middle);
@@ -275,7 +275,7 @@ static void test_pair_delete_multiple(void)
        vp = fr_pair_list_next(&local_pairs, vp);
        fr_assert(vp != NULL);
 
-       el = fr_edit_list_alloc(NULL);
+       el = fr_edit_list_alloc(NULL, 5);
        fr_assert(el != NULL);
 
        rcode = fr_edit_list_delete(el, &local_pairs, vp); /* middle */
@@ -318,7 +318,7 @@ static void test_pair_delete_multiple_abort(void)
        vp = fr_pair_list_next(&local_pairs, vp);
        TEST_CHECK(vp->da == fr_dict_attr_test_octets);
 
-       el = fr_edit_list_alloc(NULL);
+       el = fr_edit_list_alloc(NULL, 5);
        fr_assert(el != NULL);
 
        rcode = fr_edit_list_delete(el, &local_pairs, vp); /* middle */
@@ -363,7 +363,7 @@ static void test_pair_edit_value(void)
        vp = fr_pair_list_head(&local_pairs);
        fr_assert(vp != NULL);
 
-       el = fr_edit_list_alloc(NULL);
+       el = fr_edit_list_alloc(NULL, 5);
        fr_assert(el != NULL);
 
        rcode = fr_edit_list_record_value(el, vp);
@@ -397,7 +397,7 @@ static void test_pair_edit_value_abort(void)
        vp = fr_pair_list_head(&local_pairs);
        fr_assert(vp != NULL);
 
-       el = fr_edit_list_alloc(NULL);
+       el = fr_edit_list_alloc(NULL, 5);
        fr_assert(el != NULL);
 
        rcode = fr_edit_list_record_value(el, vp);
@@ -432,7 +432,7 @@ static void test_pair_insert_after_head(void)
 
        add_pairs(&local_pairs);
 
-       el = fr_edit_list_alloc(NULL);
+       el = fr_edit_list_alloc(NULL, 5);
        fr_assert(el != NULL);
 
        TEST_CHECK((vp = fr_pair_afrom_da(autofree, fr_dict_attr_test_string)) != NULL);
@@ -465,7 +465,7 @@ static void test_pair_insert_after_head_abort(void)
 
        add_pairs(&local_pairs);
 
-       el = fr_edit_list_alloc(NULL);
+       el = fr_edit_list_alloc(NULL, 5);
        fr_assert(el != NULL);
 
        TEST_CHECK((vp = fr_pair_afrom_da(autofree, fr_dict_attr_test_string)) != NULL);
@@ -501,7 +501,7 @@ static void test_pair_insert_after_middle(void)
        middle = fr_pair_list_next(&local_pairs, vp);
        fr_assert(middle != NULL);
 
-       el = fr_edit_list_alloc(NULL);
+       el = fr_edit_list_alloc(NULL, 5);
        fr_assert(el != NULL);
 
        TEST_CHECK((vp = fr_pair_afrom_da(autofree, fr_dict_attr_test_string)) != NULL);
@@ -534,7 +534,7 @@ static void test_pair_insert_after_middle_abort(void)
        middle = fr_pair_list_next(&local_pairs, vp);
        fr_assert(middle != NULL);
 
-       el = fr_edit_list_alloc(NULL);
+       el = fr_edit_list_alloc(NULL, 5);
        fr_assert(el != NULL);
 
        TEST_CHECK((vp = fr_pair_afrom_da(autofree, fr_dict_attr_test_string)) != NULL);