Skip to content

Commit 0ff0189

Browse files
committed
Avoid creation of an unused closure value in each trace op
The previous scheme created a `val showOp = <some closure>` value for each trace operation. It was unused if tracing was disabled. Still might be better to avoid its creation in the first place.
1 parent 860d102 commit 0ff0189

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

compiler/src/dotty/tools/dotc/reporting/trace.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ object trace {
2828
}
2929

3030
@inline
31-
def apply[T](question: => String, printer: Printers.Printer, show: Boolean)(op: => T)(implicit ctx: Context): T =
32-
apply[T](question, printer, if (show) showShowable(_) else alwaysToString)(op)
31+
def apply[T](question: => String, printer: Printers.Printer, show: Boolean)(op: => T)(implicit ctx: Context): T = {
32+
def op1 = op
33+
if (!Config.tracingEnabled || printer.eq(config.Printers.noPrinter)) op1
34+
else doTrace[T](question, printer, if (show) showShowable(_) else alwaysToString)(op1)
35+
}
3336

3437
@inline
3538
def apply[T](question: => String, printer: Printers.Printer)(op: => T)(implicit ctx: Context): T =

0 commit comments

Comments
 (0)