File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
src/reflect/scala/reflect/internal Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,18 @@ trait Types
107107
108108 protected val enableTypeVarExperimentals = settings.Xexperimental .value
109109
110+ /** Caching the most recent map has a 75-90% hit rate. */
111+ private object substTypeMapCache {
112+ private [this ] var cached : SubstTypeMap = new SubstTypeMap (Nil , Nil )
113+
114+ def apply (from : List [Symbol ], to : List [Type ]): SubstTypeMap = {
115+ if ((cached.from ne from) || (cached.to ne to))
116+ cached = new SubstTypeMap (from, to)
117+
118+ cached
119+ }
120+ }
121+
110122 /** The current skolemization level, needed for the algorithms
111123 * in isSameType, isSubType that do constraint solving under a prefix.
112124 */
@@ -698,8 +710,7 @@ trait Types
698710 * symbols `from` in this type.
699711 */
700712 def subst (from : List [Symbol ], to : List [Type ]): Type =
701- if (from.isEmpty) this
702- else new SubstTypeMap (from, to) apply this
713+ if (from.isEmpty) this else substTypeMapCache(from, to)(this )
703714
704715 /** Substitute symbols `to` for occurrences of symbols `from` in this type.
705716 *
Original file line number Diff line number Diff line change @@ -794,8 +794,7 @@ private[internal] trait TypeMaps {
794794 }
795795
796796 /** A map to implement the `subst` method. */
797- class SubstTypeMap (from : List [Symbol ], to : List [Type ])
798- extends SubstMap (from, to) {
797+ class SubstTypeMap (val from : List [Symbol ], val to : List [Type ]) extends SubstMap (from, to) {
799798 protected def toType (fromtp : Type , tp : Type ) = tp
800799
801800 override def mapOver (tree : Tree , giveup : () => Nothing ): Tree = {
You can’t perform that action at this time.
0 commit comments