From: Alan T. DeKok Date: Sat, 13 Nov 2021 13:50:34 +0000 (-0500) Subject: add hint for edit list size X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16d57591a35f508bc7d649d1eab251ad847b440d;p=thirdparty%2Ffreeradius-server.git add hint for edit list size so that all of the edits can (generally) live in a contiguous region of memory, and then be freed all at once. --- diff --git a/src/lib/util/edit.c b/src/lib/util/edit.c index 324e8504e1..4dbda60ff2 100644 --- a/src/lib/util/edit.c +++ b/src/lib/util/edit.c @@ -26,6 +26,7 @@ RCSID("$Id$") #include +#include #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); diff --git a/src/lib/util/edit.h b/src/lib/util/edit.h index d20d470168..7246fb45e9 100644 --- a/src/lib/util/edit.h +++ b/src/lib/util/edit.h @@ -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); diff --git a/src/lib/util/edit_tests.c b/src/lib/util/edit_tests.c index 95c7ff3a7d..f16d827b0c 100644 --- a/src/lib/util/edit_tests.c +++ b/src/lib/util/edit_tests.c @@ -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);