Browse files

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)
  • Loading branch information...
1 parent eff78b8 commit eba079b6522cc112d949c1f2c18960e31750efd6 @paulp paulp committed Jan 29, 2013
Showing with 6 additions and 6 deletions.
  1. +6 −6 src/reflect/scala/reflect/internal/Types.scala
View
12 src/reflect/scala/reflect/internal/Types.scala
@@ -746,7 +746,7 @@ trait Types extends api.Types { self: SymbolTable =>
val trivial = (
this.isTrivial
|| phase.erasedTypes && pre.typeSymbol != ArrayClass
- || pre.normalize.isTrivial && !isPossiblePrefix(clazz)
+ || skipPrefixOf(pre, clazz)
)
if (trivial) this
else {
@@ -4471,14 +4471,15 @@ trait Types extends api.Types { self: SymbolTable =>
*/
def isPossiblePrefix(clazz: Symbol) = clazz.isClass && !clazz.isPackageClass
+ private def skipPrefixOf(pre: Type, clazz: Symbol) = (
+ (pre eq NoType) || (pre eq NoPrefix) || !isPossiblePrefix(clazz)
+ )
+
/** A map to compute the asSeenFrom method */
class AsSeenFromMap(pre: Type, clazz: Symbol) extends TypeMap with KeepOnlyTypeConstraints {
var capturedSkolems: List[Symbol] = List()
var capturedParams: List[Symbol] = List()
- private def skipPrefixOf(pre: Type, clazz: Symbol) = (
- (pre eq NoType) || (pre eq NoPrefix) || !isPossiblePrefix(clazz)
- )
override def mapOver(tree: Tree, giveup: ()=>Nothing): Tree = {
object annotationArgRewriter extends TypeMapTransformer {
private def canRewriteThis(sym: Symbol) = (
@@ -4511,8 +4512,7 @@ trait Types extends api.Types { self: SymbolTable =>
}
def apply(tp: Type): Type =
- if (skipPrefixOf(pre, clazz)) tp
- else tp match {
+ tp match {
case ThisType(sym) =>
def toPrefix(pre: Type, clazz: Symbol): Type =
if (skipPrefixOf(pre, clazz)) tp

0 comments on commit eba079b

Please sign in to comment.