Skip to content

Commit f360a33

Browse files
committed
Cache stable TASTyVersion
1 parent e152b56 commit f360a33

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tasty/src/dotty/tools/tasty/TastyVersion.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package dotty.tools.tasty
22

3-
case class TastyVersion(major: Int, minor: Int, experimental: Int) {
3+
import scala.collection.mutable
4+
5+
case class TastyVersion private(major: Int, minor: Int, experimental: Int) {
46
def isExperimental: Boolean = experimental > 0
57

68
def nextStable: TastyVersion = copy(experimental = 0)
@@ -21,4 +23,12 @@ case class TastyVersion(major: Int, minor: Int, experimental: Int) {
2123
val extra = Option.when(experimental > 0)(this)
2224
s"stable TASTy from ${min.show} to ${max.show}${extra.fold("")(e => s", or exactly ${e.show}")}"
2325
}
24-
}
26+
}
27+
28+
object TastyVersion {
29+
30+
private val cache: mutable.Map[(Int, Int, Int), TastyVersion] = mutable.Map.empty
31+
32+
def apply(major: Int, minor: Int, experimental: Int): TastyVersion =
33+
cache.getOrElseUpdate((major, minor, experimental), new TastyVersion(major, minor, experimental))
34+
}

0 commit comments

Comments
 (0)