diff options
author | Martin Odersky <odersky@gmail.com> | 2016-11-14 11:58:59 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-11-16 14:25:40 +0100 |
commit | fe20b9064fca765a38345a09aa484bfb537aa3c0 (patch) | |
tree | 99cce659b7c2fe7d79fd5c9c87ba51bcb96a7545 /src/dotty/tools/dotc/core/tasty/TreeBuffer.scala | |
parent | 97b6985c34915b58e0c81fbab464f4bd532c27d0 (diff) | |
download | dotty-fe20b9064fca765a38345a09aa484bfb537aa3c0.tar.gz dotty-fe20b9064fca765a38345a09aa484bfb537aa3c0.tar.bz2 dotty-fe20b9064fca765a38345a09aa484bfb537aa3c0.zip |
Pickle and unpickle type trees
Lots of other changes to make positions work out everywhere.
One important change is that now trees can be shared, just
as types can. This change improves memory requirements (a bit)
and also makes positions in shared trees more robust.
Diffstat (limited to 'src/dotty/tools/dotc/core/tasty/TreeBuffer.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/tasty/TreeBuffer.scala | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala b/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala index f2681ecde..67dc6076f 100644 --- a/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala +++ b/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala @@ -17,26 +17,20 @@ class TreeBuffer extends TastyBuffer(50000) { private var delta: Array[Int] = _ private var numOffsets = 0 - private type TreeAddrs = Any // really: Addr | List[Addr] - /** A map from trees to the address(es) at which a tree is pickled. There may be several * such addresses if the tree is shared. To keep the map compact, the value type is a * disjunction of a single address (which is the common case) and a list of addresses. */ - private val treeAddrs = new java.util.IdentityHashMap[Tree, TreeAddrs] + private val treeAddrs = new java.util.IdentityHashMap[Tree, Any] // really: Addr | Null - def registerTreeAddr(tree: Tree) = - treeAddrs.put(tree, - treeAddrs.get(tree) match { - case null => currentAddr - case x: Addr => x :: currentAddr :: Nil - case xs: List[_] => xs :+ currentAddr - }) - - def addrsOfTree(tree: Tree): List[Addr] = treeAddrs.get(tree) match { - case null => Nil - case addr: Addr => addr :: Nil - case addrs: List[Addr] => addrs + def registerTreeAddr(tree: Tree): Addr = treeAddrs.get(tree) match { + case null => treeAddrs.put(tree, currentAddr); currentAddr + case addr: Addr => addr + } + + def addrOfTree(tree: Tree): Option[Addr] = treeAddrs.get(tree) match { + case null => None + case addr: Addr => Some(addr) } private def offset(i: Int): Addr = Addr(offsets(i)) |