Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/main/scala/scala/async/internal/LiveVariables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ trait LiveVariables {
* A state `i` is contained in the list that is the value to which
* key `j` maps iff control can flow from state `j` to state `i`.
*/
val cfg: Map[Int, Array[Int]] = {
val cfg: IntMap[Array[Int]] = {
var res = IntMap.empty[Array[Int]]

for (as <- asyncStates) res = res.updated(as.state, as.nextStates)
Expand All @@ -158,17 +158,16 @@ trait LiveVariables {
def isPred0(state1: Int, state2: Int): Boolean =
if(state1 == state2) false
else if (seen.contains(state1)) false // breaks cycles in the CFG
else cfg get state1 match {
case Some(nextStates) =>
else cfg getOrElse(state1, null) match {
case null => false
case nextStates =>
seen += state1
var i = 0
while (i < nextStates.length) {
if (nextStates(i) == state2 || isPred0(nextStates(i), state2)) return true
i += 1
}
false
case None =>
false
}

isPred0(state1, state2)
Expand Down
11 changes: 7 additions & 4 deletions src/main/scala/scala/async/internal/StateSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ import scala.collection.JavaConverters.{asScalaIteratorConverter, iterableAsScal

// Set for StateIds, which are either small positive integers or -symbolID.
final class StateSet {
private var bitSet = new java.util.BitSet()
private var caseSet = new util.HashSet[Integer]()
def +=(stateId: Int): Unit = if (stateId > 0) bitSet.set(stateId) else caseSet.add(stateId)
def contains(stateId: Int): Boolean = if (stateId > 0 && stateId < 1024) bitSet.get(stateId) else caseSet.contains(stateId)
private val bitSet = new java.util.BitSet()
private val caseSet = new util.HashSet[Integer]()
def +=(stateId: Int): Unit = if (storeInBitSet(stateId)) bitSet.set(stateId) else caseSet.add(stateId)
def contains(stateId: Int): Boolean = if (storeInBitSet(stateId)) bitSet.get(stateId) else caseSet.contains(stateId)
private def storeInBitSet(stateId: Int) = {
stateId > 0 && stateId < 1024
}
def iterator: Iterator[Integer] = {
bitSet.stream().iterator().asScala ++ caseSet.asScala.iterator
}
Expand Down