@@ -8,7 +8,6 @@ import dotty.tools.tasty.TastyBuffer
8
8
import TastyBuffer .{Addr , NoAddr , AddrWidth }
9
9
10
10
import util .Util .bestFit
11
- import util .SparseIntArray
12
11
import config .Printers .pickling
13
12
import ast .untpd .Tree
14
13
@@ -21,23 +20,18 @@ class TreeBuffer extends TastyBuffer(50000) {
21
20
private var delta : Array [Int ] = _
22
21
private var numOffsets = 0
23
22
24
- /** A map from tree unique ids to the address index at which a tree is pickled.
25
- * Note that trees are looked up by reference equality,
26
- * so one can reliably use this function only directly after `pickler`.
27
- */
28
- private val addrOfTree = SparseIntArray ()
23
+ /** A map from trees to the address at which a tree is pickled. */
24
+ private val treeAddrs = new java.util.IdentityHashMap [Tree , Any ] // really: Addr | Null
29
25
30
- def registerTreeAddr (tree : Tree ): Addr =
31
- val id = tree.uniqueId
32
- if addrOfTree.contains(id) then Addr (addrOfTree(id))
33
- else
34
- addrOfTree(tree.uniqueId) = currentAddr.index
35
- currentAddr
26
+ def registerTreeAddr (tree : Tree ): Addr = treeAddrs.get(tree) match {
27
+ case null => treeAddrs.put(tree, currentAddr); currentAddr
28
+ case addr : Addr => addr
29
+ }
36
30
37
- def addrOfTree (tree : Tree ): Addr =
38
- val idx = tree.uniqueId
39
- if addrOfTree.contains(idx) then Addr (addrOfTree(idx))
40
- else NoAddr
31
+ def addrOfTree (tree : Tree ): Addr = treeAddrs.get(tree) match {
32
+ case null => NoAddr
33
+ case addr : Addr => addr
34
+ }
41
35
42
36
private def offset (i : Int ): Addr = Addr (offsets(i))
43
37
@@ -162,8 +156,15 @@ class TreeBuffer extends TastyBuffer(50000) {
162
156
wasted
163
157
}
164
158
165
- def adjustTreeAddrs (): Unit =
166
- addrOfTree.transform((id, addr) => adjusted(Addr (addr)).index)
159
+ def adjustTreeAddrs (): Unit = {
160
+ val it = treeAddrs.keySet.iterator
161
+ while (it.hasNext) {
162
+ val tree = it.next
163
+ treeAddrs.get(tree) match {
164
+ case addr : Addr => treeAddrs.put(tree, adjusted(addr))
165
+ }
166
+ }
167
+ }
167
168
168
169
/** Final assembly, involving the following steps:
169
170
* - compute deltas
0 commit comments