@@ -10,7 +10,7 @@ import core._
10
10
import util .Spans ._ , Types ._ , Contexts ._ , Constants ._ , Names ._ , Flags ._ , NameOps ._
11
11
import Symbols ._ , StdNames ._ , Annotations ._ , Trees ._ , Symbols ._
12
12
import Decorators ._ , DenotTransformers ._
13
- import collection .mutable
13
+ import collection .{ immutable , mutable }
14
14
import util .{Property , SourceFile , NoSource }
15
15
import NameKinds .{TempResultName , OuterSelectName }
16
16
import typer .ConstFold
@@ -734,21 +734,19 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
734
734
* Set the owner of every definition in this tree which is not itself contained in this
735
735
* tree to be `newowner`
736
736
*/
737
- def changeNonLocalOwners (newowner : Symbol )(implicit ctx : Context ): Tree = {
738
- val localOwners = mutable.HashSet [Symbol ]()
739
- val traverser = new TreeTraverser {
740
-
741
- def traverse (tree : Tree )(implicit ctx : Context ): Unit = {
742
- tree match {
743
- case _ : DefTree => if (tree.symbol ne NoSymbol ) localOwners += tree.symbol
744
- case _ => traverseChildren(tree)
745
- }
737
+ def changeNonLocalOwners (newOwner : Symbol )(implicit ctx : Context ): Tree = {
738
+ val ownerAcc = new TreeAccumulator [immutable.Set [Symbol ]] {
739
+ def apply (ss : immutable.Set [Symbol ], tree : Tree )(implicit ctx : Context ) = tree match {
740
+ case tree : DefTree =>
741
+ if (tree.symbol.exists) ss + tree.symbol.owner
742
+ else ss
743
+ case _ =>
744
+ foldOver(ss, tree)
746
745
}
747
746
}
748
- traverser.traverse(tree)
749
- val nonLocalOwners = localOwners.filter(sym => ! localOwners.contains(sym.owner)).toList.map(_.owner)
750
- val newOwners = nonLocalOwners.map(_ => newowner)
751
- new TreeTypeMap (oldOwners = nonLocalOwners, newOwners = newOwners).apply(tree)
747
+ val owners = ownerAcc(immutable.Set .empty[Symbol ], tree).toList
748
+ val newOwners = List .fill(owners.size)(newOwner)
749
+ new TreeTypeMap (oldOwners = owners, newOwners = newOwners).apply(tree)
752
750
}
753
751
754
752
/** After phase `trans`, set the owner of every definition in this tree that was formerly
0 commit comments