mirror of
https://github.com/KarolS/millfork.git
synced 2024-05-31 18:41:30 +00:00
Minor optimizations
This commit is contained in:
parent
ee47ccef5a
commit
d8c11a9c50
|
@ -160,11 +160,6 @@ case class CpuStatus(a: Status[Int] = UnknownStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
def hasSet(state: State.Value): Boolean = state match {
|
def hasSet(state: State.Value): Boolean = state match {
|
||||||
case State.A => false
|
|
||||||
case State.AH => false
|
|
||||||
case State.X => false
|
|
||||||
case State.Y => false
|
|
||||||
case State.IZ => false
|
|
||||||
case State.Z => z.contains(true)
|
case State.Z => z.contains(true)
|
||||||
case State.N => n.contains(true)
|
case State.N => n.contains(true)
|
||||||
case State.C => c.contains(true)
|
case State.C => c.contains(true)
|
||||||
|
|
|
@ -21,12 +21,16 @@ case class FlowInfo(holder: FlowHolder, index: Int, _labelUseCountMap: () => Opt
|
||||||
lazy val importanceAfter: CpuImportance = holder.importanceAfter(index)
|
lazy val importanceAfter: CpuImportance = holder.importanceAfter(index)
|
||||||
lazy val labelUseCountMap: Option[Map[String, Int]] = _labelUseCountMap()
|
lazy val labelUseCountMap: Option[Map[String, Int]] = _labelUseCountMap()
|
||||||
|
|
||||||
|
@inline
|
||||||
def hasClear(state: State.Value): Boolean = statusBefore.hasClear(state)
|
def hasClear(state: State.Value): Boolean = statusBefore.hasClear(state)
|
||||||
|
|
||||||
|
@inline
|
||||||
def hasSet(state: State.Value): Boolean = statusBefore.hasSet(state)
|
def hasSet(state: State.Value): Boolean = statusBefore.hasSet(state)
|
||||||
|
|
||||||
|
@inline
|
||||||
def isUnimportant(state: State.Value): Boolean = importanceAfter.isUnimportant(state)
|
def isUnimportant(state: State.Value): Boolean = importanceAfter.isUnimportant(state)
|
||||||
|
|
||||||
|
@inline
|
||||||
def labelUseCount(label: String): Int = labelUseCountMap.map(_.getOrElse(label, 0)).getOrElse(-1)
|
def labelUseCount(label: String): Int = labelUseCountMap.map(_.getOrElse(label, 0)).getOrElse(-1)
|
||||||
|
|
||||||
override def toString: String = holder.toString(index)
|
override def toString: String = holder.toString(index)
|
||||||
|
|
10
src/main/scala/millfork/env/Environment.scala
vendored
10
src/main/scala/millfork/env/Environment.scala
vendored
|
@ -295,18 +295,20 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
|
||||||
|
|
||||||
private def removeVariableImpl(str: String): Unit = {
|
private def removeVariableImpl(str: String): Unit = {
|
||||||
def extractThingName(fullName: String): String = {
|
def extractThingName(fullName: String): String = {
|
||||||
var result = fullName.takeWhile(_ != '.')
|
val ix = fullName.indexOf('.')
|
||||||
if (result.length == fullName.length) return result
|
if (ix < 0) return fullName
|
||||||
val suffix = fullName.drop(result.length)
|
var result = fullName.substring(0, ix)
|
||||||
|
val suffix = fullName.substring(ix)
|
||||||
if (suffix == ".return" || suffix.startsWith(".return.")) {
|
if (suffix == ".return" || suffix.startsWith(".return.")) {
|
||||||
result += ".return"
|
result += ".return"
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val strWithoutPrefix = str.stripPrefix(prefix)
|
||||||
val toRemove = things.keys.filter { n =>
|
val toRemove = things.keys.filter { n =>
|
||||||
val baseName = extractThingName(n)
|
val baseName = extractThingName(n)
|
||||||
baseName == str || baseName == str.stripPrefix(prefix)
|
baseName == str || baseName == strWithoutPrefix
|
||||||
}.toSet
|
}.toSet
|
||||||
removedThings ++= toRemove.map(_.stripPrefix(prefix))
|
removedThings ++= toRemove.map(_.stripPrefix(prefix))
|
||||||
things --= toRemove
|
things --= toRemove
|
||||||
|
|
Loading…
Reference in New Issue
Block a user