diff options
author | Paul Phillips <paulp@improving.org> | 2009-06-22 22:26:59 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-06-22 22:26:59 +0000 |
commit | 76294e00c5f3cb6101d83c7d982a2be6b6575e6a (patch) | |
tree | 143dd01960ef158a030e4b18a621c5af9b0ec0a0 | |
parent | c22ebf74e0ec17d18bf097c1d47426bd647010a5 (diff) | |
download | scala-76294e00c5f3cb6101d83c7d982a2be6b6575e6a.tar.gz scala-76294e00c5f3cb6101d83c7d982a2be6b6575e6a.tar.bz2 scala-76294e00c5f3cb6101d83c7d982a2be6b6575e6a.zip |
Removed what amounted to a no-operation in the ...
Removed what amounted to a no-operation in the synthetic case class
equals method, and removed some dead code at the source level as well.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala | 82 |
1 files changed, 31 insertions, 51 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index a2d2b0a433..d3170cfa88 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -138,14 +138,16 @@ trait SyntheticMethods { self: Analyzer => localTyper.typed(methodDef) } - /** The equality method for case classes: + /** The equality method for case classes. The argument is an Any, + * but because of boxing it will always be an Object, so a check + * is neither necessary nor useful before the cast. + * * def equals(that: Any) = - * that.isInstanceOf[AnyRef] && - * ((this eq that.asInstanceOf[AnyRef]) || + * (this eq that.asInstanceOf[AnyRef]) || * (that match { * case this.C(this.arg_1, ..., this.arg_n) => true * case _ => false - * })) + * }) */ def equalsClassMethod: Tree = { val method = equalsSym @@ -155,55 +157,33 @@ trait SyntheticMethods { self: Analyzer => val that = Ident(method.paramss.head.head) val constrParamTypes = clazz.primaryConstructor.tpe.paramTypes val hasVarArgs = !constrParamTypes.isEmpty && constrParamTypes.last.typeSymbol == RepeatedParamClass - if (false && clazz.isStatic) { - // todo: elim - val target = getMember(ScalaRunTimeModule, if (hasVarArgs) nme._equalsWithVarArgs else nme._equals) - Apply( - Select( - TypeApply( - Select(that, Any_isInstanceOf), - List(TypeTree(clazz.tpe))), - Boolean_and), - List( - Apply(gen.mkAttributedRef(target), - This(clazz) :: (method.paramss.head map Ident)))) - } else { - val (pat, guard) = { - val guards = new ListBuffer[Tree] - val params = for ((acc, cpt) <- clazz.caseFieldAccessors zip constrParamTypes) yield { - val name = context.unit.fresh.newName(clazz.pos, acc.name+"$") - val isVarArg = cpt.typeSymbol == RepeatedParamClass - guards += Apply( - Select( - Ident(name), - if (isVarArg) nme.sameElements else nme.EQ), - List(Ident(acc))) - Bind(name, - if (isVarArg) Star(Ident(nme.WILDCARD)) - else Ident(nme.WILDCARD)) - } - ( Apply(Ident(clazz.name.toTermName), params), - if (guards.isEmpty) EmptyTree - else guards reduceLeft { (g1: Tree, g2: Tree) => - Apply(Select(g1, nme.AMPAMP), List(g2)) - } - ) + val (pat, guard) = { + val guards = new ListBuffer[Tree] + val params = for ((acc, cpt) <- clazz.caseFieldAccessors zip constrParamTypes) yield { + val name = context.unit.fresh.newName(clazz.pos, acc.name+"$") + val isVarArg = cpt.typeSymbol == RepeatedParamClass + guards += Apply( + Select( + Ident(name), + if (isVarArg) nme.sameElements else nme.EQ), + List(Ident(acc))) + Bind(name, + if (isVarArg) Star(Ident(nme.WILDCARD)) + else Ident(nme.WILDCARD)) } - val isAnyRef = TypeApply( - Select(that, Any_isInstanceOf), - List(TypeTree(AnyRefClass.tpe))) - val cast = TypeApply( - Select(that, Any_asInstanceOf), - List(TypeTree(AnyRefClass.tpe))) - val eq_ = Apply(Select( This(clazz) , nme.eq), List(that setType AnyRefClass.tpe)) - val match_ = Match(that, List( - CaseDef(pat, guard, Literal(Constant(true))), - CaseDef(Ident(nme.WILDCARD), EmptyTree, Literal(Constant(false))))) - Apply( - Select(isAnyRef, Boolean_and), - List(Apply(Select(eq_, Boolean_or), - List(match_)))) + ( Apply(Ident(clazz.name.toTermName), params), + if (guards.isEmpty) EmptyTree + else guards reduceLeft { (g1: Tree, g2: Tree) => + Apply(Select(g1, nme.AMPAMP), List(g2)) + } + ) } + val eq_ = Apply(Select(This(clazz), nme.eq), List(that setType AnyRefClass.tpe)) + val match_ = Match(that, List( + CaseDef(pat, guard, Literal(Constant(true))), + CaseDef(Ident(nme.WILDCARD), EmptyTree, Literal(Constant(false))))) + + gen.mkOr(eq_, match_) } ) localTyper.typed(methodDef) |