Avoiding to recall Ipv4Int on every loop

This commit is contained in:
ThomasSession 2024-08-19 16:59:19 +10:00
parent 6701cb1dc1
commit 31669efc51
2 changed files with 2 additions and 16 deletions

View File

@ -97,7 +97,8 @@ class IP2Country private constructor(private val context: Context) {
val comps = ipv4ToCountry.asSequence()
val bestMatchCountry = comps.lastOrNull { it.key <= Ipv4Int(ip) }?.let { (_, code) ->
val ipInt = Ipv4Int(ip)
val bestMatchCountry = comps.lastOrNull { it.key <= ipInt }?.let { (_, code) ->
if (code != null) {
countryToNames[code]
} else {

View File

@ -2,10 +2,7 @@ package org.thoughtcrime.securesms.util;
import androidx.annotation.NonNull;
import com.annimon.stream.Stream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public final class ListUtil {
@ -21,16 +18,4 @@ public final class ListUtil {
return chunks;
}
@SafeVarargs
public static <T> List<T> concat(Collection<T>... items) {
//noinspection Convert2MethodRef
final List<T> concat = new ArrayList<>(Stream.of(items).map(Collection::size).reduce(0, (lhs, rhs) -> lhs+rhs));
for (Collection<T> list : items) {
concat.addAll(list);
}
return concat;
}
}