From f7ea5f7a0db63a809f8aac779543b0011e0dbdb9 Mon Sep 17 00:00:00 2001 From: Grigorii Kirgizov Date: Wed, 10 Jul 2019 13:50:46 +0300 Subject: [PATCH] Add entries to ExecutionQueue only once --- .../mps/logic/reactor/core/internal/ExecutionQueue.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ExecutionQueue.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ExecutionQueue.kt index 873cd799..eb002cf3 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ExecutionQueue.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ExecutionQueue.kt @@ -41,6 +41,7 @@ internal class ExecutionQueue( lhs, rhs -> journalIndex.compare(lhs.pos, rhs.pos) } + private val seen: MutableSet = HashSet() fun run(controller: Controller, state: ProcessingStateImpl): FeedbackStatus.NORMAL { if (execQueue.isNotEmpty()) { @@ -103,16 +104,20 @@ internal class ExecutionQueue( fun offerAll(occs: Iterable): Boolean = execQueue.addAll(occs.mapNotNull { occ -> journalIndex.activatingChunkOf(Id(occ))?.let { chunk -> - ExecPos(chunk.toPos(), occ) + ExecPos(chunk.toPos(), occ).let { + if (seen.add(it)) it else null + } } }) fun offer(posInJournal: MatchJournal.Pos, activeOcc: Occurrence): Boolean = - execQueue.offer(ExecPos(posInJournal, activeOcc)) + ExecPos(posInJournal, activeOcc).let { + if (seen.add(it)) execQueue.offer(it) else false + } // special case when position in trace corresponds to position of activated occurrence fun offer(posInJournal: MatchJournal.Pos): Boolean = - execQueue.offer(ExecPos(posInJournal, posInJournal.occ)) + offer(posInJournal, posInJournal.occ) fun isEmpty(): Boolean = execQueue.isEmpty()