Replace custom TAILQ concatenation loop by TAILQ_CONCAT(3).
Comments/OK?
diff --git sbin/pfctl/parse.y sbin/pfctl/parse.y
index d524f9e92bc..67de79215e4 100644
--- sbin/pfctl/parse.y
+++ sbin/pfctl/parse.y
@@ -5637,16 +5637,11 @@ mv_rules(struct pf_ruleset *src, struct pf_ruleset *dst)
{
struct pf_rule *r;
- while ((r = TAILQ_FIRST(src->rules.active.ptr)) != NULL) {
- TAILQ_REMOVE(src->rules.active.ptr, r, entries);
- TAILQ_INSERT_TAIL(dst->rules.active.ptr, r, entries);
+ TAILQ_FOREACH(r, src->rules.active.ptr, entries)
dst->anchor->match++;
- }
+ TAILQ_CONCAT(dst->rules.active.ptr, src->rules.active.ptr, entries);
src->anchor->match = 0;
- while ((r = TAILQ_FIRST(src->rules.inactive.ptr)) != NULL) {
- TAILQ_REMOVE(src->rules.inactive.ptr, r, entries);
- TAILQ_INSERT_TAIL(dst->rules.inactive.ptr, r, entries);
- }
+ TAILQ_CONCAT(dst->rules.inactive.ptr, src->rules.inactive.ptr, entries);
}
void
diff --git sbin/pfctl/pfctl_optimize.c sbin/pfctl/pfctl_optimize.c
index 3526dcce962..fe74c435980 100644
--- sbin/pfctl/pfctl_optimize.c
+++ sbin/pfctl/pfctl_optimize.c
@@ -687,11 +687,7 @@ reorder_rules(struct pfctl *pf, struct superblock *block,
int depth)
* it based on a more optimal skipstep order.
*/
TAILQ_INIT(&head);
- while ((por = TAILQ_FIRST(&block->sb_rules))) {
- TAILQ_REMOVE(&block->sb_rules, por, por_entry);
- TAILQ_INSERT_TAIL(&head, por, por_entry);
- }
-
+ TAILQ_CONCAT(&head, &block->sb_rules, por_entry);
while (!TAILQ_EMPTY(&head)) {
largest = 1;
@@ -712,11 +708,7 @@ reorder_rules(struct pfctl *pf, struct superblock *block,
int depth)
* Nothing useful left. Leave remaining rules in order.
*/
DEBUG("(%d) no more commonality for skip steps", depth);
- while ((por = TAILQ_FIRST(&head))) {
- TAILQ_REMOVE(&head, por, por_entry);
- TAILQ_INSERT_TAIL(&block->sb_rules, por,
- por_entry);
- }
+ TAILQ_CONCAT(&block->sb_rules, &head, por_entry);
} else {
/*
* There is commonality. Extract those common rules
@@ -830,10 +822,7 @@ block_feedback(struct pfctl *pf, struct superblock *block)
*/
TAILQ_INIT(&queue);
- while ((por1 = TAILQ_FIRST(&block->sb_rules)) != NULL) {
- TAILQ_REMOVE(&block->sb_rules, por1, por_entry);
- TAILQ_INSERT_TAIL(&queue, por1, por_entry);
- }
+ TAILQ_CONCAT(&queue, &block->sb_rules, por_entry);
while ((por1 = TAILQ_FIRST(&queue)) != NULL) {
TAILQ_REMOVE(&queue, por1, por_entry);