diff options
author | Martin Odersky <odersky@gmail.com> | 2014-12-09 11:38:12 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-12-10 18:51:53 +0100 |
commit | d4d11fe7732e436178d7fe0350e116c646452cc4 (patch) | |
tree | 51dffc77dca40a764f03fd301fd252a03896cd21 /src/dotty/tools/dotc/core/Uniques.scala | |
parent | 63505c28506445216e883309237c84448ce11a7d (diff) | |
download | dotty-d4d11fe7732e436178d7fe0350e116c646452cc4.tar.gz dotty-d4d11fe7732e436178d7fe0350e116c646452cc4.tar.bz2 dotty-d4d11fe7732e436178d7fe0350e116c646452cc4.zip |
Create TypeAlias subclass of TypeBouunds
Specialize hash consing of type aliases.
Diffstat (limited to 'src/dotty/tools/dotc/core/Uniques.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Uniques.scala | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/dotty/tools/dotc/core/Uniques.scala b/src/dotty/tools/dotc/core/Uniques.scala index 0ade58193..fee217dd3 100644 --- a/src/dotty/tools/dotc/core/Uniques.scala +++ b/src/dotty/tools/dotc/core/Uniques.scala @@ -65,30 +65,27 @@ object Uniques { } } - final class TypeBoundsUniques extends HashSet[TypeBounds](initialUniquesCapacity) with Hashable { - override def hash(x: TypeBounds): Int = x.hash + final class TypeAliasUniques extends HashSet[TypeAlias](initialUniquesCapacity) with Hashable { + override def hash(x: TypeAlias): Int = x.hash - private def findPrevious(h: Int, lo: Type, hi: Type, variance: Int): TypeBounds = { + private def findPrevious(h: Int, alias: Type, variance: Int): TypeAlias = { var e = findEntryByHash(h) while (e != null) { - if ((e.lo eq lo) && (e.hi eq hi) && (e.variance == variance)) return e + if ((e.alias eq alias) && (e.variance == variance)) return e e = nextEntryByHash(h) } e } - def enterIfNew(lo: Type, hi: Type, variance: Int): TypeBounds = { - val h = doHash(variance, lo, hi) - if (monitored) recordCaching(h, classOf[TypeBounds]) - def newBounds = - if (variance == 0) new CachedTypeBounds(lo, hi, h) - else if (variance == 1) new CoTypeBounds(lo, hi, h) - else new ContraTypeBounds(lo, hi, h) - if (h == NotCached) newBounds + def enterIfNew(alias: Type, variance: Int): TypeAlias = { + val h = doHash(variance, alias) + if (monitored) recordCaching(h, classOf[TypeAlias]) + def newAlias = new TypeAlias(alias, variance, h) + if (h == NotCached) newAlias else { - val r = findPrevious(h, lo, hi, variance) + val r = findPrevious(h, alias, variance) if (r ne null) r - else addEntryAfterScan(newBounds) + else addEntryAfterScan(newAlias) } } } |