Skip to content

Commit a949072

Browse files
committed
Optimize stillValidInOwner
1 parent 750503e commit a949072

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ object Scopes {
138138
def next(): Symbol = { val r = e.sym; e = lookupNextEntry(e); r }
139139
}
140140

141+
final def contains(sym: Symbol)(using Context): Boolean =
142+
var e = lookupEntry(sym.name)
143+
while e != null && e.sym != sym do e = lookupNextEntry(e)
144+
e != null
145+
141146
/** The denotation set of all the symbols with given name in this scope
142147
* Symbols occur in the result in reverse order relative to their occurrence
143148
* in `this.toList`.

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -2357,19 +2357,17 @@ object SymDenotations {
23572357
stillValidInOwner(denot)
23582358
}
23592359

2360-
private[SymDenotations] def stillValidInOwner(denot: SymDenotation)(using Context): Boolean = try {
2360+
private[SymDenotations] def stillValidInOwner(denot: SymDenotation)(using Context): Boolean = try
23612361
val owner = denot.owner.denot
2362-
stillValid(owner) && (
2362+
stillValid(owner)
2363+
&& (
23632364
!owner.isClass
23642365
|| owner.isRefinementClass
23652366
|| owner.is(Scala2x)
2366-
|| (owner.unforcedDecls.lookupAll(denot.name) contains denot.symbol)
2367+
|| owner.unforcedDecls.contains(denot.symbol)
23672368
|| denot.isSelfSym
23682369
|| denot.isLocalDummy)
2369-
}
2370-
catch {
2371-
case ex: StaleSymbol => false
2372-
}
2370+
catch case ex: StaleSymbol => false
23732371

23742372
/** Explain why symbol is invalid; used for debugging only */
23752373
def traceInvalid(denot: Denotation)(using Context): Boolean = {

0 commit comments

Comments
 (0)