From 50120b991fc2fa4b7813096de87b42d700faf3e6 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 17 Nov 2020 16:56:43 +0000 Subject: [PATCH] database: Simplify network matching code Signed-off-by: Michael Tremer --- src/database.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/database.c b/src/database.c index 51cb5cd..1a354f6 100644 --- a/src/database.c +++ b/src/database.c @@ -1129,12 +1129,6 @@ static int loc_database_enumerator_stack_push_node( return 0; } -static int loc_network_match_countries(struct loc_network* network, struct loc_country_list* countries) { - const char* country_code = loc_network_get_country_code(network); - - return loc_country_list_contains_code(countries, country_code); -} - static int loc_network_match_asns(struct loc_network* network, struct loc_as_list* asns) { uint32_t asn = loc_network_get_asn(network); @@ -1148,8 +1142,14 @@ static int loc_database_enumerator_filter_network( return 1; // Skip if the country code does not match - if (enumerator->countries && !loc_network_match_countries(network, enumerator->countries)) - return 1; + if (enumerator->countries) { + if (!loc_country_list_empty(enumerator->countries)) { + const char* country_code = loc_network_get_country_code(network); + + if (!loc_country_list_contains_code(enumerator->countries, country_code)) + return 1; + } + } // Skip if the ASN does not match if (enumerator->asns && !loc_network_match_asns(network, enumerator->asns)) -- 2.39.2