Skip to content

Commit 97d8171

Browse files
Cache stable TASTyVersion
Co-authored-by: Nicolas Stucki <nicolas.stucki@gmail.com> Co-authored-by: Jamie Thompson <bishbashboshjt@gmail.com>
1 parent e152b56 commit 97d8171

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

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

Lines changed: 17 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.annotation.internal.sharable
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,17 @@ 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+
@sharable
31+
private val cache: java.util.concurrent.ConcurrentHashMap[TastyVersion, TastyVersion] =
32+
new java.util.concurrent.ConcurrentHashMap()
33+
34+
def apply(major: Int, minor: Int, experimental: Int): TastyVersion = {
35+
val version = new TastyVersion(major, minor, experimental)
36+
val cachedVersion = cache.putIfAbsent(version, version)
37+
if (cachedVersion == null) version else cachedVersion
38+
}
39+
}

0 commit comments

Comments
 (0)