diff options
author | Paul Phillips <paulp@improving.org> | 2011-01-03 20:17:30 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-01-03 20:17:30 +0000 |
commit | d891167c880d56c38d145d19e2f825ec908eec61 (patch) | |
tree | f135fef0b4baf35efa4e4510277fc4c6c608b986 /src | |
parent | 4f9b1cf852a62fc5ec7cd2dd9a36f7d6391f58fb (diff) | |
download | scala-d891167c880d56c38d145d19e2f825ec908eec61.tar.gz scala-d891167c880d56c38d145d19e2f825ec908eec61.tar.bz2 scala-d891167c880d56c38d145d19e2f825ec908eec61.zip |
Some minor Tree optimizations. No review.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/Trees.scala | 7 | ||||
-rwxr-xr-x | src/library/scala/reflect/generic/Trees.scala | 14 |
2 files changed, 9 insertions, 12 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index 7f52d40053..ecba1c23da 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -89,8 +89,7 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable => def equalsStructure(that : Tree) = equalsStructure0(that)(_ eq _) def equalsStructure0(that: Tree)(f: (Tree,Tree) => Boolean): Boolean = - (tree == that) || ((tree.getClass == that.getClass) && { // XXX defining any kind of equality in terms of getClass is a mistake - assert(tree.productArity == that.productArity) + f(tree, that) || ((tree.productArity == that.productArity) && { def equals0(this0: Any, that0: Any): Boolean = (this0, that0) match { case (x: Tree, y: Tree) => f(x, y) || (x equalsStructure0 y)(f) case (xs: List[_], ys: List[_]) => (xs corresponds ys)(equals0) @@ -103,7 +102,7 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable => true } - (tree.productIterator.toList corresponds that.productIterator.toList)(equals0) && compareOriginals() + (tree.productIterator zip that.productIterator forall { case (x, y) => equals0(x, y) }) && compareOriginals() }) def shallowDuplicate: Tree = new ShallowDuplicator(tree) transform tree @@ -948,6 +947,8 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable => class TreeTypeSubstituter(val from: List[Symbol], val to: List[Type]) extends Traverser { val typeSubst = new SubstTypeMap(from, to) + def fromContains = typeSubst.fromContains + override def traverse(tree: Tree) { if (tree.tpe ne null) tree.tpe = typeSubst(tree.tpe) if (tree.isDef) { diff --git a/src/library/scala/reflect/generic/Trees.scala b/src/library/scala/reflect/generic/Trees.scala index 2573b6b191..6493c4f667 100755 --- a/src/library/scala/reflect/generic/Trees.scala +++ b/src/library/scala/reflect/generic/Trees.scala @@ -104,10 +104,10 @@ trait Trees { self: Universe => */ def children: List[Tree] = { def subtrees(x: Any): List[Tree] = x match { - case EmptyTree => List() - case t: Tree => List(t) + case EmptyTree => Nil + case t: Tree => List(t) case xs: List[_] => xs flatMap subtrees - case _ => List() + case _ => Nil } productIterator.toList flatMap subtrees } @@ -135,12 +135,8 @@ trait Trees { self: Universe => buffer.toString } - override def hashCode(): Int = super.hashCode() - - override def equals(that: Any): Boolean = that match { - case t: Tree => this eq t - case _ => false - } + final override def hashCode(): Int = System.identityHashCode(this) + final override def equals(that: Any) = this eq that.asInstanceOf[AnyRef] } private[scala] def duplicateTree(tree: Tree): Tree = tree |