Skip to content

Commit 4fb358c

Browse files
committed
Micro-optimization: Symbol#denot
1 parent a516a4e commit 4fb358c

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,19 +398,30 @@ object Symbols {
398398

399399
/** The last denotation of this symbol */
400400
private[this] var lastDenot: SymDenotation = _
401+
private[this] var checkedPeriod: Period = Nowhere
401402

402403
/** Set the denotation of this symbol */
403-
private[core] def denot_=(d: SymDenotation) =
404+
private[core] def denot_=(d: SymDenotation) = {
404405
lastDenot = d
406+
checkedPeriod = Nowhere
407+
}
405408

406409
/** The current denotation of this symbol */
407410
final def denot(implicit ctx: Context): SymDenotation = {
408-
var denot = lastDenot
409-
if (!(denot.validFor contains ctx.period)) {
410-
denot = denot.current.asInstanceOf[SymDenotation]
411-
lastDenot = denot
411+
val lastd = lastDenot
412+
if (checkedPeriod == ctx.period) lastd
413+
else computeDenot(lastd)
414+
}
415+
416+
private def computeDenot(lastd: SymDenotation)(implicit ctx: Context): SymDenotation = {
417+
val now = ctx.period
418+
checkedPeriod = now
419+
if (lastd.validFor contains now) lastd
420+
else {
421+
val newd = lastd.current.asInstanceOf[SymDenotation]
422+
lastDenot = newd
423+
newd
412424
}
413-
denot
414425
}
415426

416427
/** The initial denotation of this symbol, without going through `current` */

0 commit comments

Comments
 (0)