[#828] | project: compiler | priority: low | category: missing feature | |
---|---|---|---|---|
submitter | assigned to | status | date submitted | |
Nikolay | Martin | fixed | 2006-11-16 17:36:50.0 | |
subject | [contrib #250] generated equals should include identity test | |||
code |
def equalsMethod: Tree = { val target = getMember(ScalaRunTimeModule, nme._equals) val paramtypes = if (target.tpe.paramTypes.isEmpty) List() else target.tpe.paramTypes.tail val method = syntheticMethod( nme.equals_, 0, MethodType(paramtypes, target.tpe.resultType)) typed(DefDef(method, vparamss => Apply( Select( Apply( Select(Ident(vparamss.head.head), Object_eq), List(This(clazz))), Boolean_or), List( Apply( Select( TypeApply( Select(Ident(vparamss.head.head), Any_isInstanceOf), List(TypeTree(clazz.tpe))), Boolean_and), List( Apply(gen.mkAttributedRef(target), This(clazz) :: (vparamss.head map Ident)))))))); } |
|||
what happened | current "equals" methods do an instanceof test and then call the scala runtime's equal method. i believe this ca\ n be shortcircuited for the case where the object is being tested against itself for equality. the modification \ to the generator for the equals method given above seems to do the trick. |
|||
what expected | case class .equals method needs to be as efficient as possible, particularly when hash-consing is being used. | |||
[back to overview] |
Nikolay edited on 2006-11-16 17:39:13.0 |
This is a contribution (#250) from Ross Judson. Martin, what do you say? |
Nikolay edited on 2006-11-17 11:25:15.0 |