diff options
author | Paul Phillips <paulp@improving.org> | 2009-11-04 06:36:03 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-11-04 06:36:03 +0000 |
commit | f5ede0923cd8dd2d45853a06e71e05052e462213 (patch) | |
tree | 731d9f9314e9a1762dd9f513cce15dff8b231829 /src/compiler | |
parent | b02b388ffaa5ea6d62669bb91d8af6de521aa71f (diff) | |
download | scala-f5ede0923cd8dd2d45853a06e71e05052e462213.tar.gz scala-f5ede0923cd8dd2d45853a06e71e05052e462213.tar.bz2 scala-f5ede0923cd8dd2d45853a06e71e05052e462213.zip |
Scala implementation of fancier hashCode algori...
Scala implementation of fancier hashCode algorithm. At the moment it
isn't used unless you supply -Yjenkins-hashCodes to scalac. Without the
flag, the supplied test case generates 12559 unique hashCodes among
90000 case class instances; with the flag it generates 89999.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/Settings.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala | 11 |
2 files changed, 8 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala index f6221ac14b..95c3a56767 100644 --- a/src/compiler/scala/tools/nsc/Settings.scala +++ b/src/compiler/scala/tools/nsc/Settings.scala @@ -837,6 +837,7 @@ trait ScalacSettings { val Ypmatdebug = BooleanSetting ("-Ypmat-debug", "Trace all pattern matcher activity.") val Ytailrec = BooleanSetting ("-Ytailrecommend", "Alert methods which would be tail-recursive if private or final.") val YhigherKindedRaw = BooleanSetting ("-Yhigher-kinded-raw", "(temporary!) Treat raw Java types as higher-kinded types.") + val Yjenkins = BooleanSetting ("-Yjenkins-hashCodes", "Use jenkins hash algorithm for case class generated hashCodes.") // Equality specific val logEqEq = BooleanSetting ("-Ylog-eqeq", "Log all noteworthy equality tests") . diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index e3d75752f2..a3f628ebb4 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -109,8 +109,8 @@ trait SyntheticMethods extends ast.TreeDSL { typer typed { DEF(method) === LIT(clazz.name.decode) } } - def forwardingMethod(name: Name): Tree = { - val target = getMember(ScalaRunTimeModule, "_" + name) + def forwardingMethod(name: Name, targetName: Name): Tree = { + val target = getMember(ScalaRunTimeModule, targetName) val paramtypes = target.tpe.paramTypes drop 1 val method = syntheticMethod( name, 0, makeTypeConstructor(paramtypes, target.tpe.resultType) @@ -123,6 +123,9 @@ trait SyntheticMethods extends ast.TreeDSL { } } + def hashCodeTarget: Name = + if (settings.Yjenkins.value) "hashCodeJenkins" else nme.hashCode_ + def equalsSym = syntheticMethod( nme.equals_, 0, makeTypeConstructor(List(AnyClass.tpe), BooleanClass.tpe) ) @@ -244,8 +247,8 @@ trait SyntheticMethods extends ast.TreeDSL { // methods for case classes only def classMethods = List( - Object_hashCode -> (() => forwardingMethod(nme.hashCode_)), - Object_toString -> (() => forwardingMethod(nme.toString_)), + Object_hashCode -> (() => forwardingMethod(nme.hashCode_, "_" + hashCodeTarget)), + Object_toString -> (() => forwardingMethod(nme.toString_, "_" + nme.toString_)), Object_equals -> (() => equalsClassMethod) ) // methods for case objects only |