Skip to content

Commit

Permalink
Cache stable TASTyVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Nov 23, 2023
1 parent e152b56 commit 9597a61
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tasty/src/dotty/tools/tasty/TastyVersion.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dotty.tools.tasty

case class TastyVersion(major: Int, minor: Int, experimental: Int) {
case class TastyVersion private(major: Int, minor: Int, experimental: Int) {
def isExperimental: Boolean = experimental > 0

def nextStable: TastyVersion = copy(experimental = 0)
Expand All @@ -21,4 +21,16 @@ case class TastyVersion(major: Int, minor: Int, experimental: Int) {
val extra = Option.when(experimental > 0)(this)
s"stable TASTy from ${min.show} to ${max.show}${extra.fold("")(e => s", or exactly ${e.show}")}"
}
}
}

object TastyVersion {

private val cache: java.util.concurrent.ConcurrentHashMap[TastyVersion, TastyVersion] =
new java.util.concurrent.ConcurrentHashMap()

def apply(major: Int, minor: Int, experimental: Int): TastyVersion = {
val version = new TastyVersion(major, minor, experimental)
val cachedVersion = cache.putIfAbsent(version, version)
if (cachedVersion == null) version else cachedVersion
}
}

0 comments on commit 9597a61

Please sign in to comment.