Skip to content

Commit eba079b

Browse files
committed
Optimization in AsSeenFromMap.
Despite all the eyes which have traveled over this code, we all managed to miss this: // Note that pre and clazz are fixed at construction class AsSeenFromMap(pre: Type, clazz: Symbol) { ... def apply(tp: Type): Type = if (skipPrefixOf(pre, clazz)) tp else ... } Additionally, the exclusion condition in asSeenFrom contained a useless check, here: // !isPossiblePrefix(clazz) alone is enough pre.normalize.isTrivial && !isPossiblePrefix(clazz)
1 parent eff78b8 commit eba079b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/reflect/scala/reflect/internal/Types.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ trait Types extends api.Types { self: SymbolTable =>
746746
val trivial = (
747747
this.isTrivial
748748
|| phase.erasedTypes && pre.typeSymbol != ArrayClass
749-
|| pre.normalize.isTrivial && !isPossiblePrefix(clazz)
749+
|| skipPrefixOf(pre, clazz)
750750
)
751751
if (trivial) this
752752
else {
@@ -4471,14 +4471,15 @@ trait Types extends api.Types { self: SymbolTable =>
44714471
*/
44724472
def isPossiblePrefix(clazz: Symbol) = clazz.isClass && !clazz.isPackageClass
44734473

4474+
private def skipPrefixOf(pre: Type, clazz: Symbol) = (
4475+
(pre eq NoType) || (pre eq NoPrefix) || !isPossiblePrefix(clazz)
4476+
)
4477+
44744478
/** A map to compute the asSeenFrom method */
44754479
class AsSeenFromMap(pre: Type, clazz: Symbol) extends TypeMap with KeepOnlyTypeConstraints {
44764480
var capturedSkolems: List[Symbol] = List()
44774481
var capturedParams: List[Symbol] = List()
44784482

4479-
private def skipPrefixOf(pre: Type, clazz: Symbol) = (
4480-
(pre eq NoType) || (pre eq NoPrefix) || !isPossiblePrefix(clazz)
4481-
)
44824483
override def mapOver(tree: Tree, giveup: ()=>Nothing): Tree = {
44834484
object annotationArgRewriter extends TypeMapTransformer {
44844485
private def canRewriteThis(sym: Symbol) = (
@@ -4511,8 +4512,7 @@ trait Types extends api.Types { self: SymbolTable =>
45114512
}
45124513

45134514
def apply(tp: Type): Type =
4514-
if (skipPrefixOf(pre, clazz)) tp
4515-
else tp match {
4515+
tp match {
45164516
case ThisType(sym) =>
45174517
def toPrefix(pre: Type, clazz: Symbol): Type =
45184518
if (skipPrefixOf(pre, clazz)) tp

0 commit comments

Comments
 (0)