diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-01-22 15:43:12 +0100 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-01-30 09:33:33 -0800 |
commit | 6357c8d1fc6a850b5d83f78a44044bc90f60e03b (patch) | |
tree | 979c249aa33f5a9ffcb1f0a7d1edee6e53b24cf4 | |
parent | 14d8c222aa5f810fea34d35dc5f50d7f17ddc091 (diff) | |
download | scala-6357c8d1fc6a850b5d83f78a44044bc90f60e03b.tar.gz scala-6357c8d1fc6a850b5d83f78a44044bc90f60e03b.tar.bz2 scala-6357c8d1fc6a850b5d83f78a44044bc90f60e03b.zip |
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
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala | 10 | ||||
-rw-r--r-- | src/reflect/scala/reflect/api/Symbols.scala | 3 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala index a9714acc55..d00e0e6bf6 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala +++ b/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 = { diff --git a/src/reflect/scala/reflect/api/Symbols.scala b/src/reflect/scala/reflect/api/Symbols.scala index 36f8626389..b53c700701 100644 --- a/src/reflect/scala/reflect/api/Symbols.scala +++ b/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 */ |