From bd6b23858ba2678bc2909ae0a4c19e853ad3b9c3 Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 25 May 2021 15:38:24 -0400 Subject: [PATCH] Refine processLines --- .../vpnhotspot/net/monitor/IpNeighbourMonitor.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt index b0e07773..2b55761b 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt @@ -4,6 +4,7 @@ import be.mygod.vpnhotspot.net.IpDev import be.mygod.vpnhotspot.net.IpNeighbour import kotlinx.collections.immutable.PersistentMap import kotlinx.collections.immutable.persistentMapOf +import kotlinx.collections.immutable.toPersistentMap import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.channels.* @@ -71,11 +72,11 @@ class IpNeighbourMonitor private constructor() : IpMonitor() { } override suspend fun processLines(lines: Sequence) { - neighbours = lines - .flatMap { IpNeighbour.parse(it, fullMode).asSequence() } - .filter { it.state != IpNeighbour.State.DELETING } // skip entries without lladdr - .associateByTo(persistentMapOf().builder()) { IpDev(it) } - .build() + neighbours = mutableMapOf().apply { + for (line in lines) for (neigh in IpNeighbour.parse(line, fullMode)) { + if (neigh.state != IpNeighbour.State.DELETING) this[IpDev(neigh)] = neigh + } + }.toPersistentMap() aggregator.trySendBlocking(neighbours).onFailure { throw it!! } } }