Skip to content

Commit

Permalink
Specialize hashCode in TypeRef from the generic MurmurHashCode3 imple…
Browse files Browse the repository at this point in the history
…mentation.
  • Loading branch information
odersky authored and gkossakowski committed Aug 20, 2012
1 parent 2a2d923 commit 3b7c730
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/reflect/scala/reflect/internal/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,8 @@ trait Types extends api.Types { self: SymbolTable =>
* A type that can be passed to unique(..) and be stored in the uniques map.
*/
abstract class UniqueType extends Type with Product {
final override val hashCode = scala.runtime.ScalaRunTime._hashCode(this)
final override val hashCode = computeHashCode
protected def computeHashCode = scala.runtime.ScalaRunTime._hashCode(this)
}

/** A base class for types that defer some operations
Expand Down Expand Up @@ -2341,6 +2342,19 @@ trait Types extends api.Types { self: SymbolTable =>
private[reflect] var baseTypeSeqCache: BaseTypeSeq = _
private[reflect] var baseTypeSeqPeriod = NoPeriod
private var normalized: Type = _

//OPT specialize hashCode
override final def computeHashCode = {
import scala.util.hashing.MurmurHash3._
val hasArgs = args.nonEmpty
var h = productSeed
h = mix(h, pre.hashCode)
h = mix(h, sym.hashCode)
if (hasArgs)
finalizeHash(mix(h, args.hashCode), 3)
else
finalizeHash(h, 2)
}

// @M: propagate actual type params (args) to `tp`, by replacing
// formal type parameters with actual ones. If tp is higher kinded,
Expand Down

0 comments on commit 3b7c730

Please sign in to comment.