mirror of
https://github.com/KarolS/millfork.git
synced 2025-03-21 06:30:14 +00:00
Minor compilation speed optimization
This commit is contained in:
parent
a92f24b280
commit
c0eae29a41
src/main/scala/millfork
@ -662,7 +662,12 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
|
||||
|
||||
def eval(e: Expression, vars: Map[String, Constant]): Option[Constant] = evalImpl(e, Some(vars))
|
||||
|
||||
def eval(e: Expression): Option[Constant] = evalImpl(e, None)
|
||||
def eval(e: Expression): Option[Constant] = {
|
||||
if (e.constantValueCache ne null) return e.constantValueCache
|
||||
val cv = evalImpl(e, None)
|
||||
e.constantValueCache = cv
|
||||
cv
|
||||
}
|
||||
|
||||
//noinspection ScalaUnnecessaryParentheses,ZeroIndexToHead
|
||||
private def evalImpl(e: Expression, vv: Option[Map[String, Constant]]): Option[Constant] = try{{
|
||||
|
@ -54,6 +54,7 @@ sealed trait Expression extends Node {
|
||||
def #-#(that: Expression): Expression = SumExpression(List(false -> this, true -> that), decimal = false)
|
||||
|
||||
@transient var typeCache: Type = _
|
||||
@transient var constantValueCache: Option[Constant] = _
|
||||
}
|
||||
|
||||
case class ConstantArrayElementExpression(constant: Constant) extends Expression {
|
||||
|
@ -806,7 +806,7 @@ object MfParser {
|
||||
val identifierTail: P[String] =
|
||||
CharsWhileIn("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_.1234567890", min = 1).rep(min = 1, sep = "$").!
|
||||
|
||||
val identifier: P[String] = (letter ~ ("$".? ~ identifierTail).?).!.opaque("<identifier>")
|
||||
val identifier: P[String] = (letter ~ ("$".? ~ identifierTail).?).!.map(_.intern()).opaque("<identifier>")
|
||||
|
||||
val doubleQuotedString: P[String] = P("\"" ~/ CharsWhile(c => c != '\"' && c != '\n' && c != '\r').?.! ~ "\"")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user