@@ -10,7 +10,7 @@ import core._
1010import util .Spans ._ , Types ._ , Contexts ._ , Constants ._ , Names ._ , Flags ._ , NameOps ._
1111import Symbols ._ , StdNames ._ , Annotations ._ , Trees ._ , Symbols ._
1212import Decorators ._ , DenotTransformers ._
13- import collection .mutable
13+ import collection .{ immutable , mutable }
1414import util .{Property , SourceFile , NoSource }
1515import NameKinds .{TempResultName , OuterSelectName }
1616import typer .ConstFold
@@ -734,21 +734,19 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
734734 * Set the owner of every definition in this tree which is not itself contained in this
735735 * tree to be `newowner`
736736 */
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)
746745 }
747746 }
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)
752750 }
753751
754752 /** After phase `trans`, set the owner of every definition in this tree that was formerly
0 commit comments