Loading packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/Merge.kt +3 −3 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ import com.android.systemui.kairos.internal.constInit import com.android.systemui.kairos.internal.mapImpl import com.android.systemui.kairos.internal.mergeNodes import com.android.systemui.kairos.internal.mergeNodesLeft import com.android.systemui.kairos.internal.store.ConcurrentHashMapK import com.android.systemui.kairos.internal.store.HashMapK import com.android.systemui.kairos.internal.switchDeferredImpl import com.android.systemui.kairos.internal.switchPromptImpl import com.android.systemui.kairos.util.map Loading Loading @@ -205,7 +205,7 @@ fun <K, V> Incremental<K, Events<V>>.mergeEventsIncrementally(): Events<Map<K, V .asIterable() }, getPatches = { patches }, storeFactory = ConcurrentHashMapK.Factory(), storeFactory = HashMapK.Factory(), ) .awaitValues(), ) Loading Loading @@ -250,7 +250,7 @@ fun <K, V> Incremental<K, Events<V>>.mergeEventsIncrementallyPromptly(): Events< .asIterable() }, getPatches = { patches }, storeFactory = ConcurrentHashMapK.Factory(), storeFactory = HashMapK.Factory(), ) .awaitValues(), ) Loading packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/DeferScope.kt +1 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ internal class DeferScopeImpl : DeferScope { } override fun <R> deferAsync(block: () -> R): Lazy<R> = lazy(block).also { deferrals.add { it.value } } lazy(LazyThreadSafetyMode.NONE, block).also { deferrals.add { it.value } } } internal class CompletableLazy<T>( Loading packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/Demux.kt +14 −13 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package com.android.systemui.kairos.internal import com.android.systemui.kairos.internal.store.ConcurrentHashMapK import com.android.systemui.kairos.internal.store.HashMapK import com.android.systemui.kairos.internal.store.MapHolder import com.android.systemui.kairos.internal.store.MapK import com.android.systemui.kairos.internal.store.MutableMapK Loading @@ -33,7 +33,7 @@ internal class DemuxNode<W, K, A>( lateinit var upstreamConnection: NodeConnection<MapK<W, K, A>> @Volatile private var epoch: Long = Long.MIN_VALUE private var epoch: Long = Long.MIN_VALUE fun hasCurrentValueLocked(logIndent: Int, evalScope: EvalScope, key: K): Boolean = evalScope.epoch == epoch && Loading @@ -52,15 +52,16 @@ internal class DemuxNode<W, K, A>( upstreamConnection.getPushEvent(currentLogIndent, evalScope) } updateEpoch(evalScope) for ((key, _) in upstreamResult) { if (!branchNodeByKey.contains(key)) continue upstreamResult.forEach { key, _ -> if (branchNodeByKey.contains(key)) { val branch = branchNodeByKey.getValue(key) branch.schedule(currentLogIndent, evalScope) } } } override fun adjustDirectUpstream(scheduler: Scheduler, oldDepth: Int, newDepth: Int) { for ((_, branchNode) in branchNodeByKey) { branchNodeByKey.forEach { _, branchNode -> branchNode.downstreamSet.adjustDirectUpstream(scheduler, oldDepth, newDepth) } } Loading @@ -71,7 +72,7 @@ internal class DemuxNode<W, K, A>( oldIndirectSet: Set<MuxDeferredNode<*, *, *>>, newDirectDepth: Int, ) { for ((_, branchNode) in branchNodeByKey) { branchNodeByKey.forEach { _, branchNode -> branchNode.downstreamSet.moveIndirectUpstreamToDirect( scheduler, oldIndirectDepth, Loading @@ -88,7 +89,7 @@ internal class DemuxNode<W, K, A>( removals: Set<MuxDeferredNode<*, *, *>>, additions: Set<MuxDeferredNode<*, *, *>>, ) { for ((_, branchNode) in branchNodeByKey) { branchNodeByKey.forEach { _, branchNode -> branchNode.downstreamSet.adjustIndirectUpstream( scheduler, oldDepth, Loading @@ -105,7 +106,7 @@ internal class DemuxNode<W, K, A>( newIndirectDepth: Int, newIndirectSet: Set<MuxDeferredNode<*, *, *>>, ) { for ((_, branchNode) in branchNodeByKey) { branchNodeByKey.forEach { _, branchNode -> branchNode.downstreamSet.moveDirectUpstreamToIndirect( scheduler, oldDirectDepth, Loading @@ -121,14 +122,14 @@ internal class DemuxNode<W, K, A>( indirectSet: Set<MuxDeferredNode<*, *, *>>, ) { lifecycle.lifecycleState = DemuxLifecycleState.Dead for ((_, branchNode) in branchNodeByKey) { branchNodeByKey.forEach { _, branchNode -> branchNode.downstreamSet.removeIndirectUpstream(scheduler, depth, indirectSet) } } override fun removeDirectUpstream(scheduler: Scheduler, depth: Int) { lifecycle.lifecycleState = DemuxLifecycleState.Dead for ((_, branchNode) in branchNodeByKey) { branchNodeByKey.forEach { _, branchNode -> branchNode.downstreamSet.removeDirectUpstream(scheduler, depth) } } Loading Loading @@ -217,7 +218,7 @@ internal fun <K, A> demuxMap( upstream: EvalScope.() -> EventsImpl<Map<K, A>>, numKeys: Int?, ): DemuxImpl<K, A> = DemuxImpl(mapImpl(upstream) { it, _ -> MapHolder(it) }, numKeys, ConcurrentHashMapK.Factory()) DemuxImpl(mapImpl(upstream) { it, _ -> MapHolder(it) }, numKeys, HashMapK.Factory()) internal class DemuxActivator<W, K, A>( private val numKeys: Int?, Loading packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/Graph.kt +21 −13 Original line number Diff line number Diff line Loading @@ -61,14 +61,14 @@ import java.util.TreeMap */ internal class DepthTracker { @Volatile var snapshotIsDirect = true @Volatile private var snapshotIsIndirectRoot = false var snapshotIsDirect = true private var snapshotIsIndirectRoot = false private inline val snapshotIsIndirect: Boolean get() = !snapshotIsDirect @Volatile var snapshotIndirectDepth: Int = 0 @Volatile var snapshotDirectDepth: Int = 0 var snapshotIndirectDepth: Int = 0 var snapshotDirectDepth: Int = 0 private val _snapshotIndirectRoots = HashSet<MuxDeferredNode<*, *, *>>() val snapshotIndirectRoots Loading @@ -79,10 +79,10 @@ internal class DepthTracker { private val dirty_directUpstreamDepths = TreeMap<Int, Int>() private val dirty_indirectUpstreamDepths = TreeMap<Int, Int>() private val dirty_indirectUpstreamRoots = Bag<MuxDeferredNode<*, *, *>>() @Volatile var dirty_directDepth = 0 @Volatile private var dirty_indirectDepth = 0 @Volatile private var dirty_depthIsDirect = true @Volatile private var dirty_isIndirectRoot = false var dirty_directDepth = 0 private var dirty_indirectDepth = 0 private var dirty_depthIsDirect = true private var dirty_isIndirectRoot = false fun schedule(scheduler: Scheduler, node: MuxNode<*, *, *>) { if (dirty_depthIsDirect) { Loading Loading @@ -182,7 +182,7 @@ internal class DepthTracker { return (!dirty_depthIsDirect && (addsChanged || removalsChanged)) } private fun <T> HashSet<T>.applyRemovalDiff(changeSet: Set<T>): Set<T> { private fun <T> HashSet<T>.applyRemovalDiff(changeSet: HashSet<T>): Set<T> { val remainder = HashSet<T>() for (element in changeSet) { if (!remove(element)) { Loading Loading @@ -479,9 +479,17 @@ internal fun scheduleAll( downstreamSet: DownstreamSet, evalScope: EvalScope, ): Boolean { downstreamSet.nodes.forEach { it.schedule(logIndent, evalScope) } downstreamSet.muxMovers.forEach { it.scheduleMover(logIndent, evalScope) } downstreamSet.outputs.forEach { it.schedule(logIndent, evalScope) } downstreamSet.stateWriters.forEach { evalScope.schedule(it) } for (node in downstreamSet.nodes) { node.schedule(logIndent, evalScope) } for (mover in downstreamSet.muxMovers) { mover.scheduleMover(logIndent, evalScope) } for (output in downstreamSet.outputs) { output.schedule(logIndent, evalScope) } for (idx in downstreamSet.stateWriters.indices) { evalScope.schedule(downstreamSet.stateWriters[idx]) } return downstreamSet.isNotEmpty() } packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/IncrementalImpl.kt +2 −2 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ private fun <K, V> Map<K, V>.applyPatchCalm( val current = this val filteredPatch = mutableMapOf<K, Maybe<V>>() val new = current.toMutableMap() for ((key, change) in patch) { patch.forEach { key, change -> when (change) { is Maybe.Present -> { if (key !in current || current.getValue(key) != change.value) { Loading @@ -93,7 +93,7 @@ private fun <K, V> Map<K, V>.applyPatchCalm( return if (filteredPatch.isNotEmpty()) filteredPatch to new else null } internal inline fun <K, V> EventsImpl<Map<K, Maybe<V>>>.calmUpdates( internal fun <K, V> EventsImpl<Map<K, Maybe<V>>>.calmUpdates( state: StateDerived<Map<K, V>> ): Pair<EventsImpl<Map<K, Maybe<V>>>, EventsImpl<Map<K, V>>> { val maybeUpdate = Loading Loading
packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/Merge.kt +3 −3 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ import com.android.systemui.kairos.internal.constInit import com.android.systemui.kairos.internal.mapImpl import com.android.systemui.kairos.internal.mergeNodes import com.android.systemui.kairos.internal.mergeNodesLeft import com.android.systemui.kairos.internal.store.ConcurrentHashMapK import com.android.systemui.kairos.internal.store.HashMapK import com.android.systemui.kairos.internal.switchDeferredImpl import com.android.systemui.kairos.internal.switchPromptImpl import com.android.systemui.kairos.util.map Loading Loading @@ -205,7 +205,7 @@ fun <K, V> Incremental<K, Events<V>>.mergeEventsIncrementally(): Events<Map<K, V .asIterable() }, getPatches = { patches }, storeFactory = ConcurrentHashMapK.Factory(), storeFactory = HashMapK.Factory(), ) .awaitValues(), ) Loading Loading @@ -250,7 +250,7 @@ fun <K, V> Incremental<K, Events<V>>.mergeEventsIncrementallyPromptly(): Events< .asIterable() }, getPatches = { patches }, storeFactory = ConcurrentHashMapK.Factory(), storeFactory = HashMapK.Factory(), ) .awaitValues(), ) Loading
packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/DeferScope.kt +1 −1 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ internal class DeferScopeImpl : DeferScope { } override fun <R> deferAsync(block: () -> R): Lazy<R> = lazy(block).also { deferrals.add { it.value } } lazy(LazyThreadSafetyMode.NONE, block).also { deferrals.add { it.value } } } internal class CompletableLazy<T>( Loading
packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/Demux.kt +14 −13 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package com.android.systemui.kairos.internal import com.android.systemui.kairos.internal.store.ConcurrentHashMapK import com.android.systemui.kairos.internal.store.HashMapK import com.android.systemui.kairos.internal.store.MapHolder import com.android.systemui.kairos.internal.store.MapK import com.android.systemui.kairos.internal.store.MutableMapK Loading @@ -33,7 +33,7 @@ internal class DemuxNode<W, K, A>( lateinit var upstreamConnection: NodeConnection<MapK<W, K, A>> @Volatile private var epoch: Long = Long.MIN_VALUE private var epoch: Long = Long.MIN_VALUE fun hasCurrentValueLocked(logIndent: Int, evalScope: EvalScope, key: K): Boolean = evalScope.epoch == epoch && Loading @@ -52,15 +52,16 @@ internal class DemuxNode<W, K, A>( upstreamConnection.getPushEvent(currentLogIndent, evalScope) } updateEpoch(evalScope) for ((key, _) in upstreamResult) { if (!branchNodeByKey.contains(key)) continue upstreamResult.forEach { key, _ -> if (branchNodeByKey.contains(key)) { val branch = branchNodeByKey.getValue(key) branch.schedule(currentLogIndent, evalScope) } } } override fun adjustDirectUpstream(scheduler: Scheduler, oldDepth: Int, newDepth: Int) { for ((_, branchNode) in branchNodeByKey) { branchNodeByKey.forEach { _, branchNode -> branchNode.downstreamSet.adjustDirectUpstream(scheduler, oldDepth, newDepth) } } Loading @@ -71,7 +72,7 @@ internal class DemuxNode<W, K, A>( oldIndirectSet: Set<MuxDeferredNode<*, *, *>>, newDirectDepth: Int, ) { for ((_, branchNode) in branchNodeByKey) { branchNodeByKey.forEach { _, branchNode -> branchNode.downstreamSet.moveIndirectUpstreamToDirect( scheduler, oldIndirectDepth, Loading @@ -88,7 +89,7 @@ internal class DemuxNode<W, K, A>( removals: Set<MuxDeferredNode<*, *, *>>, additions: Set<MuxDeferredNode<*, *, *>>, ) { for ((_, branchNode) in branchNodeByKey) { branchNodeByKey.forEach { _, branchNode -> branchNode.downstreamSet.adjustIndirectUpstream( scheduler, oldDepth, Loading @@ -105,7 +106,7 @@ internal class DemuxNode<W, K, A>( newIndirectDepth: Int, newIndirectSet: Set<MuxDeferredNode<*, *, *>>, ) { for ((_, branchNode) in branchNodeByKey) { branchNodeByKey.forEach { _, branchNode -> branchNode.downstreamSet.moveDirectUpstreamToIndirect( scheduler, oldDirectDepth, Loading @@ -121,14 +122,14 @@ internal class DemuxNode<W, K, A>( indirectSet: Set<MuxDeferredNode<*, *, *>>, ) { lifecycle.lifecycleState = DemuxLifecycleState.Dead for ((_, branchNode) in branchNodeByKey) { branchNodeByKey.forEach { _, branchNode -> branchNode.downstreamSet.removeIndirectUpstream(scheduler, depth, indirectSet) } } override fun removeDirectUpstream(scheduler: Scheduler, depth: Int) { lifecycle.lifecycleState = DemuxLifecycleState.Dead for ((_, branchNode) in branchNodeByKey) { branchNodeByKey.forEach { _, branchNode -> branchNode.downstreamSet.removeDirectUpstream(scheduler, depth) } } Loading Loading @@ -217,7 +218,7 @@ internal fun <K, A> demuxMap( upstream: EvalScope.() -> EventsImpl<Map<K, A>>, numKeys: Int?, ): DemuxImpl<K, A> = DemuxImpl(mapImpl(upstream) { it, _ -> MapHolder(it) }, numKeys, ConcurrentHashMapK.Factory()) DemuxImpl(mapImpl(upstream) { it, _ -> MapHolder(it) }, numKeys, HashMapK.Factory()) internal class DemuxActivator<W, K, A>( private val numKeys: Int?, Loading
packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/Graph.kt +21 −13 Original line number Diff line number Diff line Loading @@ -61,14 +61,14 @@ import java.util.TreeMap */ internal class DepthTracker { @Volatile var snapshotIsDirect = true @Volatile private var snapshotIsIndirectRoot = false var snapshotIsDirect = true private var snapshotIsIndirectRoot = false private inline val snapshotIsIndirect: Boolean get() = !snapshotIsDirect @Volatile var snapshotIndirectDepth: Int = 0 @Volatile var snapshotDirectDepth: Int = 0 var snapshotIndirectDepth: Int = 0 var snapshotDirectDepth: Int = 0 private val _snapshotIndirectRoots = HashSet<MuxDeferredNode<*, *, *>>() val snapshotIndirectRoots Loading @@ -79,10 +79,10 @@ internal class DepthTracker { private val dirty_directUpstreamDepths = TreeMap<Int, Int>() private val dirty_indirectUpstreamDepths = TreeMap<Int, Int>() private val dirty_indirectUpstreamRoots = Bag<MuxDeferredNode<*, *, *>>() @Volatile var dirty_directDepth = 0 @Volatile private var dirty_indirectDepth = 0 @Volatile private var dirty_depthIsDirect = true @Volatile private var dirty_isIndirectRoot = false var dirty_directDepth = 0 private var dirty_indirectDepth = 0 private var dirty_depthIsDirect = true private var dirty_isIndirectRoot = false fun schedule(scheduler: Scheduler, node: MuxNode<*, *, *>) { if (dirty_depthIsDirect) { Loading Loading @@ -182,7 +182,7 @@ internal class DepthTracker { return (!dirty_depthIsDirect && (addsChanged || removalsChanged)) } private fun <T> HashSet<T>.applyRemovalDiff(changeSet: Set<T>): Set<T> { private fun <T> HashSet<T>.applyRemovalDiff(changeSet: HashSet<T>): Set<T> { val remainder = HashSet<T>() for (element in changeSet) { if (!remove(element)) { Loading Loading @@ -479,9 +479,17 @@ internal fun scheduleAll( downstreamSet: DownstreamSet, evalScope: EvalScope, ): Boolean { downstreamSet.nodes.forEach { it.schedule(logIndent, evalScope) } downstreamSet.muxMovers.forEach { it.scheduleMover(logIndent, evalScope) } downstreamSet.outputs.forEach { it.schedule(logIndent, evalScope) } downstreamSet.stateWriters.forEach { evalScope.schedule(it) } for (node in downstreamSet.nodes) { node.schedule(logIndent, evalScope) } for (mover in downstreamSet.muxMovers) { mover.scheduleMover(logIndent, evalScope) } for (output in downstreamSet.outputs) { output.schedule(logIndent, evalScope) } for (idx in downstreamSet.stateWriters.indices) { evalScope.schedule(downstreamSet.stateWriters[idx]) } return downstreamSet.isNotEmpty() }
packages/SystemUI/utils/kairos/src/com/android/systemui/kairos/internal/IncrementalImpl.kt +2 −2 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ private fun <K, V> Map<K, V>.applyPatchCalm( val current = this val filteredPatch = mutableMapOf<K, Maybe<V>>() val new = current.toMutableMap() for ((key, change) in patch) { patch.forEach { key, change -> when (change) { is Maybe.Present -> { if (key !in current || current.getValue(key) != change.value) { Loading @@ -93,7 +93,7 @@ private fun <K, V> Map<K, V>.applyPatchCalm( return if (filteredPatch.isNotEmpty()) filteredPatch to new else null } internal inline fun <K, V> EventsImpl<Map<K, Maybe<V>>>.calmUpdates( internal fun <K, V> EventsImpl<Map<K, Maybe<V>>>.calmUpdates( state: StateDerived<Map<K, V>> ): Pair<EventsImpl<Map<K, Maybe<V>>>, EventsImpl<Map<K, V>>> { val maybeUpdate = Loading