From: Michael Tremer Date: Wed, 6 Mar 2024 22:45:28 +0000 (+0000) Subject: tree: Be smarter when removing networks from the stack X-Git-Tag: 0.9.18~101 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e5e53b597033d1884f69a3eebac473b4b4695828;p=location%2Flibloc.git tree: Be smarter when removing networks from the stack Since we are working through a sorted tree, we will either only see subnets of a network or we won't. Once we see a network that isn't a subnet, we remove the supernet until nothing is left on the stack. Signed-off-by: Michael Tremer --- diff --git a/src/network-tree.c b/src/network-tree.c index 4359308..fcc4239 100644 --- a/src/network-tree.c +++ b/src/network-tree.c @@ -492,11 +492,7 @@ static int loc_network_tree_dedup_step(struct loc_network* network, void* data) if (loc_network_list_empty(ctx->stack)) return loc_network_list_push(ctx->stack, network); - const unsigned int prefix = loc_network_prefix(network); - - // Remove any networks that are not interesting - loc_network_list_remove_with_prefix_smaller_than(ctx->stack, prefix); - + // Walk through all networks on the stack... for (int i = loc_network_list_size(ctx->stack) - 1; i >= 0; i--) { n = loc_network_list_get(ctx->stack, i); @@ -519,6 +515,12 @@ static int loc_network_tree_dedup_step(struct loc_network* network, void* data) break; } + // If the network wasn't a subnet, we can remove it, + // because we won't ever see a subnet again. + r = loc_network_list_remove(ctx->stack, n); + if (r) + goto END; + loc_network_unref(n); n = NULL; }