Skip to content

Commit

Permalink
cleanups as per unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Aug 22, 2023
1 parent af6a524 commit f863c81
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/lib/util/pair.c
Original file line number Diff line number Diff line change
Expand Up @@ -3325,21 +3325,8 @@ bool fr_pair_matches_da(void const *item, void const *uctx)
*/
static void pair_list_flatten(TALLOC_CTX *ctx, fr_pair_list_t *to, fr_pair_list_t *from)
{
bool skip = true;
fr_pair_t *vp, *next;

/*
* If the list is already flat, don't do anything.
*/
for (vp = fr_pair_list_head(from); vp; vp = fr_pair_list_next(from, vp)) {
if (fr_type_is_structural(vp->vp_type)) {
skip = false;
break;
}
}

if (skip) return;

/*
* Sort the source list before flattening it. This is
* really necessary only for struct and tlv types. But
Expand Down Expand Up @@ -3407,10 +3394,28 @@ void fr_pair_flatten(fr_pair_t *vp)
{
fr_pair_list_t list;

fr_pair_list_init(&list);

fr_assert(fr_type_is_structural(vp->vp_type));

/*
* Don't flatten children of a group if they're already flat.
*/
if (vp->vp_type == FR_TYPE_GROUP) {
bool skip = true;

/*
* If the list is already flat, don't do anything.
*/
fr_pair_list_foreach(&vp->vp_group, child) {
if (fr_type_is_structural(child->vp_type)) {
skip = false;
break;
}
}
if (skip) return;
}

fr_pair_list_init(&list);

/*
* Flatten to an intermediate list, so that we don't loop
* over things we already flattened.
Expand Down

0 comments on commit f863c81

Please sign in to comment.