Skip to content

Commit 5ae8020

Browse files
authored
fix: removing in memory context creation for every event (#110)
1 parent 13d1596 commit 5ae8020

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/main/kotlin/at/ac/uibk/dps/cirrina/execution/object/Extent.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package at.ac.uibk.dps.cirrina.execution.`object`
22

3-
class Extent private constructor(private val contexts: Array<Context>) {
3+
class Extent
4+
private constructor(
5+
private val contexts: Array<Context>,
6+
private val overlay: Map<String, Any?> = emptyMap(),
7+
) {
48
val high: Context? = contexts.lastOrNull()
59

610
fun setOrCreate(name: String, value: Any?): Int =
@@ -12,13 +16,16 @@ class Extent private constructor(private val contexts: Array<Context>) {
1216
?: error("variable '$name' not found in any context")
1317

1418
fun resolve(name: String): Any =
15-
contexts.lastOrNull { it.has(name) }?.get(name)
19+
overlay[name]
20+
?: contexts.lastOrNull { it.has(name) }?.get(name)
1621
?: error("variable '$name' not found in any context")
1722

18-
fun has(name: String): Boolean = contexts.any { it.has(name) }
23+
fun has(name: String): Boolean = name in overlay || contexts.any { it.has(name) }
1924

2025
fun extend(high: Context): Extent = Extent(contexts + high)
2126

27+
fun with(overlay: Map<String, Any?>): Extent = Extent(contexts, overlay)
28+
2229
companion object {
2330
fun empty() = Extent(emptyArray())
2431

src/main/kotlin/at/ac/uibk/dps/cirrina/execution/object/StateMachine.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import TimeoutActionManager
44
import at.ac.uibk.dps.cirrina.Runtime
55
import at.ac.uibk.dps.cirrina.csm.Csml.EventChannel
66
import at.ac.uibk.dps.cirrina.execution.`object`.StateMachine.Factory
7-
import at.ac.uibk.dps.cirrina.execution.provider.ContextInMemory
87
import at.ac.uibk.dps.cirrina.spec.Instance
98
import at.ac.uibk.dps.cirrina.spec.StateMachine as StateMachineSpec
109
import at.ac.uibk.dps.cirrina.spec.Transition as TransitionSpec
@@ -140,11 +139,7 @@ internal constructor(
140139
if (candidates.isEmpty()) return null
141140

142141
val evalExtent =
143-
activeState!!
144-
.extent
145-
.extend(
146-
ContextInMemory().apply { event.data.forEach { create(VAR_PREFIX + it.name, it.value) } }
147-
)
142+
activeState!!.extent.with(event.data.associate { VAR_PREFIX + it.name to it.value })
148143

149144
return trySelect(candidates, evalExtent)?.also {
150145
event.data.forEach { d -> extent.setOrCreate(VAR_PREFIX + d.name, d.value) }

0 commit comments

Comments
 (0)