Skip to content

Commit 4625098

Browse files
committed
Better caching of sources
1 parent 8674fb6 commit 4625098

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,20 @@ object Contexts {
270270

271271
def getSource(fileName: String): SourceFile = {
272272
val f = new PlainFile(Path(fileName))
273-
if (f.isDirectory) {
274-
error(s"expected file, received directory '$fileName'")
275-
NoSource
276-
}
277-
else if (f.exists)
278-
getSource(f)
279-
else {
280-
error(s"not found: $fileName")
281-
NoSource
273+
base.sources.get(f) match {
274+
case Some(source) =>
275+
source
276+
case None =>
277+
if (f.isDirectory) {
278+
error(s"expected file, received directory '$fileName'")
279+
NoSource
280+
}
281+
else if (f.exists)
282+
getSource(f)
283+
else {
284+
error(s"not found: $fileName")
285+
NoSource
286+
}
282287
}
283288
}
284289

@@ -466,10 +471,11 @@ object Contexts {
466471
final def withOwner(owner: Symbol): Context =
467472
if (owner ne this.owner) fresh.setOwner(owner) else this
468473

469-
private[this] var sourceCtx: SimpleIdentityMap[SourceFile, Context] = SimpleIdentityMap.Empty
474+
private var sourceCtx: SimpleIdentityMap[SourceFile, Context] = SimpleIdentityMap.Empty
470475

471476
final def withSource(source: SourceFile): Context =
472477
if (source `eq` this.source) this
478+
else if ((source `eq` outer.source) && (outer.sourceCtx(this.source) `eq` this)) outer
473479
else {
474480
val prev = sourceCtx(source)
475481
if (prev != null) prev

0 commit comments

Comments
 (0)