Skip to content

Commit f0fb487

Browse files
committed
Slight code refactoring
Avoid redundant computations when already in printing mode.
1 parent f31563a commit f0fb487

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,19 @@ trait Reporting { this: Context =>
149149
else traceIndented[T](s"==> $question?", (res: Any) => s"<== $question = ${resStr(res)}")(op)
150150
}
151151

152-
def traceIndented[T](leading: => String, trailing: Any => String)(op: => T): T = {
153-
var finalized = false
154-
var logctx = this
155-
while (logctx.reporter.isInstanceOf[StoreReporter]) logctx = logctx.outer
156-
def finalize(result: Any, note: String) =
157-
if (!finalized) {
158-
base.indent -= 1
159-
logctx.log(s"${base.indentTab * base.indent}${trailing(result)}$note")
160-
finalized = true
161-
}
152+
def traceIndented[T](leading: => String, trailing: Any => String)(op: => T): T =
162153
if (ctx.mode.is(Mode.Printing)) op
163-
else try {
154+
else {
155+
var finalized = false
156+
var logctx = this
157+
while (logctx.reporter.isInstanceOf[StoreReporter]) logctx = logctx.outer
158+
def finalize(result: Any, note: String) =
159+
if (!finalized) {
160+
base.indent -= 1
161+
logctx.log(s"${base.indentTab * base.indent}${trailing(result)}$note")
162+
finalized = true
163+
}
164+
try {
164165
logctx.log(s"${base.indentTab * base.indent}$leading")
165166
base.indent += 1
166167
val res = op

0 commit comments

Comments
 (0)