Skip to content

Commit b89e713

Browse files
committed
Streamline trace implementation
Avoid creation of `op1` methods if tracing is not enabled.
1 parent 1209646 commit b89e713

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,30 @@ object trace {
1414
conditionally(ctx.settings.YdebugTrace.value, question, false)(op)
1515

1616
@inline
17-
def conditionally[TC](cond: Boolean, question: => String, show: Boolean)(op: => TC)(implicit ctx: Context): TC = {
18-
def op1 = op
19-
if (Config.tracingEnabled && cond) apply[TC](question, Printers.default, show)(op1)
20-
else op1
21-
}
17+
def conditionally[TC](cond: Boolean, question: => String, show: Boolean)(op: => TC)(implicit ctx: Context): TC =
18+
if (Config.tracingEnabled) {
19+
def op1 = op
20+
if (cond) apply[TC](question, Printers.default, show)(op1)
21+
else op1
22+
} else op
2223

2324
@inline
24-
def apply[T](question: => String, printer: Printers.Printer, showOp: Any => String)(op: => T)(implicit ctx: Context): T = {
25-
def op1 = op
26-
if (!Config.tracingEnabled || printer.eq(config.Printers.noPrinter)) op1
27-
else doTrace[T](question, printer, showOp)(op1)
28-
}
25+
def apply[T](question: => String, printer: Printers.Printer, showOp: Any => String)(op: => T)(implicit ctx: Context): T =
26+
if (Config.tracingEnabled) {
27+
def op1 = op
28+
if (printer.eq(config.Printers.noPrinter)) op1
29+
else doTrace[T](question, printer, showOp)(op1)
30+
}
31+
else op
2932

3033
@inline
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-
}
34+
def apply[T](question: => String, printer: Printers.Printer, show: Boolean)(op: => T)(implicit ctx: Context): T =
35+
if (Config.tracingEnabled) {
36+
def op1 = op
37+
if (printer.eq(config.Printers.noPrinter)) op1
38+
else doTrace[T](question, printer, if (show) showShowable(_) else alwaysToString)(op1)
39+
}
40+
else op
3641

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

0 commit comments

Comments
 (0)