@@ -11,7 +11,7 @@ import Decorators._
11
11
import ast .Trees ._
12
12
import MegaPhase ._
13
13
import StdNames .nme
14
- import Names .TermName
14
+ import Names ._
15
15
import Constants .Constant
16
16
17
17
@@ -28,14 +28,15 @@ class Instrumentation extends MiniPhase { thisPhase =>
28
28
ctx.settings.YinstrumentClosures .value ||
29
29
ctx.settings.YinstrumentAllocations .value
30
30
31
+ private val namesOfInterest = List (" ::" , " +=" , " toString" )
32
+ private var namesToRecord : Set [Name ] = _
33
+
31
34
private var consName : TermName = _
32
35
private var consEqName : TermName = _
33
36
34
- override def prepareForUnit (tree : Tree )(using Context ): Context = {
35
- consName = " ::" .toTermName
36
- consEqName = " +=" .toTermName
37
+ override def prepareForUnit (tree : Tree )(using Context ): Context =
38
+ namesToRecord = namesOfInterest.map(_.toTermName).toSet
37
39
ctx
38
- }
39
40
40
41
private def record (category : String , tree : Tree )(using Context ): Tree = {
41
42
val key = Literal (Constant (s " $category${tree.sourcePos.show}" ))
@@ -45,8 +46,8 @@ class Instrumentation extends MiniPhase { thisPhase =>
45
46
override def transformApply (tree : Apply )(using Context ): Tree = tree.fun match {
46
47
case Select (nu : New , _) =>
47
48
cpy.Block (tree)(record(i " alloc/ ${nu.tpe}@ " , tree) :: Nil , tree)
48
- case Select (_, name) if name == consName || name == consEqName =>
49
- cpy.Block (tree)(record(" alloc/:: " , tree) :: Nil , tree)
49
+ case Select (_, name) if namesToRecord.contains( name) =>
50
+ cpy.Block (tree)(record(i " alloc/ $name " , tree) :: Nil , tree)
50
51
case _ =>
51
52
tree
52
53
}
0 commit comments