From 06177d8c6004bf8b54322d92926152a7656f9c2a Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 24 Nov 2020 16:57:28 +0000 Subject: [PATCH] network-list: Use binary search to find if a network is a subnet Signed-off-by: Michael Tremer --- src/network.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/network.c b/src/network.c index febab95..394bafc 100644 --- a/src/network.c +++ b/src/network.c @@ -697,19 +697,18 @@ LOC_EXPORT struct loc_network_list* loc_network_exclude_list( while (!loc_network_list_empty(to_check)) { struct loc_network* subnet_to_check = loc_network_list_pop(to_check); + // Check whether the subnet to check is part of the input list + if (loc_network_list_contains(list, subnet_to_check)) { + loc_network_unref(subnet_to_check); + continue; + } + // Marks whether this subnet passed all checks int passed = 1; for (unsigned int i = 0; i < loc_network_list_size(list); i++) { subnet = loc_network_list_get(list, i); - // Drop this subnet if is is already in list - if (loc_network_cmp(subnet_to_check, subnet) == 0) { - passed = 0; - loc_network_unref(subnet); - break; - } - // Drop this subnet if is a subnet of another subnet if (loc_network_is_subnet(subnet_to_check, subnet)) { passed = 0; -- 2.39.2