Skip to content

Commit f612425

Browse files
committed
More performance improvements to FlowMap
1 parent 491111d commit f612425

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

  • util/src/main/kotlin/com/caplin/integration/datasourcex/util/flow

util/src/main/kotlin/com/caplin/integration/datasourcex/util/flow/FlowMap.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,12 @@ private class FlowMapImpl<K : Any, V : Any>(initialMap: PersistentMap<K, V>) :
133133
emit(it)
134134
if (held != null) {
135135
var nextVersion = version + 1
136-
while (held?.containsKey(nextVersion) == true) {
137-
val next = held!!.remove(nextVersion)!!
136+
var next: FlowMapEvent<K, V>? = held?.remove(nextVersion)
137+
while (next != null) {
138138
emit(next)
139139
version = next.state.version
140140
nextVersion = version + 1
141+
next = held?.remove(nextVersion)
141142
}
142143
if (held?.isEmpty() == true) held = null
143144
}
@@ -158,16 +159,16 @@ private class FlowMapImpl<K : Any, V : Any>(initialMap: PersistentMap<K, V>) :
158159
if (first) {
159160
val map = flowMapEvent.state.map
160161
if (predicate == null) {
161-
for (entry in map.entries) {
162+
for (entry in map) {
162163
emit(Upsert(entry.key, null, entry.value))
163164
}
164165
} else {
165-
for (entry in map.entries) {
166-
val key = entry.key
167-
val value = entry.value
168-
if (predicate(key, value)) {
169-
emittedKeys!!.add(key)
170-
emit(Upsert(key, null, value))
166+
for (entry in map) {
167+
val k = entry.key
168+
val v = entry.value
169+
if (predicate(k, v)) {
170+
emittedKeys!!.add(k)
171+
emit(Upsert(k, null, v))
171172
}
172173
}
173174
}

0 commit comments

Comments
 (0)