mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-18 23:28:26 +00:00
Avoiding to recall Ipv4Int on every loop
This commit is contained in:
parent
6701cb1dc1
commit
31669efc51
@ -97,7 +97,8 @@ class IP2Country private constructor(private val context: Context) {
|
|||||||
|
|
||||||
val comps = ipv4ToCountry.asSequence()
|
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) {
|
if (code != null) {
|
||||||
countryToNames[code]
|
countryToNames[code]
|
||||||
} else {
|
} else {
|
||||||
|
@ -2,10 +2,7 @@ package org.thoughtcrime.securesms.util;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.annimon.stream.Stream;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class ListUtil {
|
public final class ListUtil {
|
||||||
@ -21,16 +18,4 @@ public final class ListUtil {
|
|||||||
|
|
||||||
return chunks;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user