From 784de3487d469051639b4c23cdff8d2f5599a919 Mon Sep 17 00:00:00 2001 From: bemusementpark Date: Sun, 6 Oct 2024 13:27:32 +1030 Subject: [PATCH] Simplify cacheCountryForIP --- .../thoughtcrime/securesms/util/IP2Country.kt | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/IP2Country.kt b/app/src/main/java/org/thoughtcrime/securesms/util/IP2Country.kt index d3fedd86d7..19c629785e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/IP2Country.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/IP2Country.kt @@ -111,26 +111,16 @@ class IP2Country private constructor(private val context: Context) { } private fun cacheCountryForIP(ip: String): String? { - // return early if cached countryNamesCache[ip]?.let { return it } val ipInt = ipv4Int(ip) - val bestMatchCountry = ipv4ToCountry.floorEntry(ipInt)?.let { (_, code) -> - if (code != null) { - countryToNames[code] - } else { - null - } - } + val bestMatchCountry = ipv4ToCountry.floorEntry(ipInt)?.value?.let { countryToNames[it] } - if (bestMatchCountry != null) { - countryNamesCache[ip] = bestMatchCountry - return bestMatchCountry - } else { - Log.d("Loki","Country name for $ip couldn't be found") - } - return null + if (bestMatchCountry != null) countryNamesCache[ip] = bestMatchCountry + else Log.d("Loki","Country name for $ip couldn't be found") + + return bestMatchCountry } private fun populateCacheIfNeeded() {