Skip to content

Commit 1dd8196

Browse files
committed
Optimize SuperAccessors#needsProtectedAccessor
Avoid an expensive call to hostForAccessorOf if possible.
1 parent e0ef928 commit 1dd8196

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ class SuperAccessors(thisPhase: DenotTransformer) {
299299
*/
300300
private def needsProtectedAccessor(sym: Symbol, pos: Position)(implicit ctx: Context): Boolean = {
301301
val clazz = currentClass
302-
val host = hostForAccessorOf(sym, clazz)
303302
def accessibleThroughSubclassing =
304303
validCurrentClass && clazz.classInfo.selfType.derivesFrom(sym.owner) && !clazz.is(Trait)
305304

@@ -311,7 +310,13 @@ class SuperAccessors(thisPhase: DenotTransformer) {
311310
&& (sym.enclosingPackageClass != currentClass.enclosingPackageClass)
312311
&& (sym.enclosingPackageClass == sym.accessBoundary(sym.enclosingPackageClass))
313312
)
313+
314+
if (!isCandidate)
315+
return false
316+
317+
val host = hostForAccessorOf(sym, clazz)
314318
val hostSelfType = host.classInfo.selfType
319+
315320
def isSelfType = !(host.appliedRef <:< hostSelfType) && {
316321
if (hostSelfType.typeSymbol.is(JavaDefined))
317322
ctx.restrictionError(
@@ -326,7 +331,7 @@ class SuperAccessors(thisPhase: DenotTransformer) {
326331
)
327332
true
328333
}
329-
isCandidate && !host.is(Package) && !isSelfType && !isJavaProtected
334+
!host.is(Package) && !isSelfType && !isJavaProtected
330335
}
331336

332337
/** Return the innermost enclosing class C of referencingClass for which either

0 commit comments

Comments
 (0)