Skip to content

Commit 9597a61

Browse files
committed
Cache stable TASTyVersion
1 parent e152b56 commit 9597a61

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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

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

3-
case class TastyVersion(major: Int, minor: Int, experimental: Int) {
3+
case class TastyVersion private(major: Int, minor: Int, experimental: Int) {
44
def isExperimental: Boolean = experimental > 0
55

66
def nextStable: TastyVersion = copy(experimental = 0)
@@ -21,4 +21,16 @@ case class TastyVersion(major: Int, minor: Int, experimental: Int) {
2121
val extra = Option.when(experimental > 0)(this)
2222
s"stable TASTy from ${min.show} to ${max.show}${extra.fold("")(e => s", or exactly ${e.show}")}"
2323
}
24-
}
24+
}
25+
26+
object TastyVersion {
27+
28+
private val cache: java.util.concurrent.ConcurrentHashMap[TastyVersion, TastyVersion] =
29+
new java.util.concurrent.ConcurrentHashMap()
30+
31+
def apply(major: Int, minor: Int, experimental: Int): TastyVersion = {
32+
val version = new TastyVersion(major, minor, experimental)
33+
val cachedVersion = cache.putIfAbsent(version, version)
34+
if (cachedVersion == null) version else cachedVersion
35+
}
36+
}

0 commit comments

Comments
 (0)