Skip to content

Commit 85094bd

Browse files
oderskynicolasstucki
authored andcommitted
Compare sourcefiles structurally
Avoid using `eq` for comparing sourcefiles. Optimize `equals` with a fastpath for identical sourcefiles instead.
1 parent 6bc0bb7 commit 85094bd

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ abstract class Positioned(implicit @transientParam src: SourceFile) extends Prod
7575
case _ =>
7676
def include(span: Span, x: Any): Span = x match {
7777
case p: Positioned =>
78-
if (p.source `ne` src) span
78+
if (p.source != src) span
7979
else if (p.span.exists) span.union(p.span)
8080
else if (span.exists) {
8181
if (span.end != MaxOffset)

compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class PositionPickler(pickler: TastyPickler, addrOfTree: untpd.Tree => Option[Ad
7272
def traverse(x: Any, current: SourceFile): Unit = x match {
7373
case x: untpd.Tree =>
7474
if (x.span.exists) {
75-
val sourceChange = x.source `ne` current
75+
val sourceChange = x.source != current
7676
val needsPos = x.span.toSynthetic != x.envelope(x.source) || alwaysNeedsPos(x)
7777
addrOfTree(x) match {
7878
case Some(addr)

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class Typer extends Namer
228228
*/
229229
def isDefinedInCurrentUnit(denot: Denotation)(implicit ctx: Context): Boolean = denot match {
230230
case MultiDenotation(d1, d2) => isDefinedInCurrentUnit(d1) || isDefinedInCurrentUnit(d2)
231-
case denot: SingleDenotation => denot.symbol.source `eq` ctx.compilationUnit.source
231+
case denot: SingleDenotation => denot.symbol.source == ctx.compilationUnit.source
232232
}
233233

234234
/** Is `denot` the denotation of a self symbol? */

compiler/src/dotty/tools/dotc/util/SourceFile.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,14 @@ class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends
6060

6161
def pathName: PathName = file.absolutePath.toTermName
6262

63-
override def equals(that : Any): Boolean = that match {
64-
case that : SourceFile => file == that.file && start == that.start
65-
case _ => false
66-
}
63+
override def equals(that: Any): Boolean =
64+
(this `eq` that.asInstanceOf[AnyRef]) || {
65+
that match {
66+
case that : SourceFile => file == that.file && start == that.start
67+
case _ => false
68+
}
69+
}
70+
6771
override def hashCode: Int = file.hashCode * 41 + start.hashCode
6872

6973
def apply(idx: Int): Char = content().apply(idx)

0 commit comments

Comments
 (0)