Skip to content
Browse files

SI-6726 Further optimization of pattern analysis

Manually fuse `.filterNot(..).map` in dropUnit.

Before:

    real    1m23.574s
    user    1m51.795s
    sys 0m2.634s

After:

    real    1m4.883s
    user    1m30.754s
    sys 0m1.776s
  • Loading branch information...
1 parent 14d8c22 commit 6357c8d1fc6a850b5d83f78a44044bc90f60e03b @retronym retronym committed with adriaanm Jan 22, 2013
View
10 src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
@@ -2070,6 +2070,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
import scala.collection.mutable.ArrayBuffer
type FormulaBuilder = ArrayBuffer[Clause]
def formulaBuilder = ArrayBuffer[Clause]()
+ def formulaBuilderSized(init: Int) = new ArrayBuffer[Clause](init)
def addFormula(buff: FormulaBuilder, f: Formula): Unit = buff ++= f
def toFormula(buff: FormulaBuilder): Formula = buff
@@ -2223,13 +2224,18 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
}
private def withLit(res: Model, l: Lit): Model = if (res eq NoModel) NoModel else res + (l.sym -> l.pos)
- private def dropUnit(f: Formula, unitLit: Lit) = {
+ private def dropUnit(f: Formula, unitLit: Lit): Formula = {
val negated = -unitLit
// drop entire clauses that are trivially true
// (i.e., disjunctions that contain the literal we're making true in the returned model),
// and simplify clauses by dropping the negation of the literal we're making true
// (since False \/ X == X)
- f.filterNot(_.contains(unitLit)).map(_ - negated)
+ val dropped = formulaBuilderSized(f.size)
+ for {
+ clause <- f
+ if !(clause contains unitLit)
+ } dropped += (clause - negated)
+ dropped
}
def findModelFor(f: Formula): Model = {
View
3 src/reflect/scala/reflect/api/Symbols.scala
@@ -351,8 +351,7 @@ trait Symbols { self: Universe =>
def asFreeType: FreeTypeSymbol = throw new ScalaReflectionException(s"$this is not a free type")
/** @group Constructors */
- def
- newTermSymbol(name: TermName, pos: Position = NoPosition, flags: FlagSet = NoFlags): TermSymbol
+ def newTermSymbol(name: TermName, pos: Position = NoPosition, flags: FlagSet = NoFlags): TermSymbol
/** @group Constructors */
def newModuleAndClassSymbol(name: Name, pos: Position = NoPosition, flags: FlagSet = NoFlags): (ModuleSymbol, ClassSymbol)
/** @group Constructors */

0 comments on commit 6357c8d

Please sign in to comment.
Something went wrong with that request. Please try again.