Skip to content

Commit

Permalink
Move to concurrenthashmap for the pattern cache
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenamar-db committed Dec 20, 2024
1 parent ce8a931 commit aee46d2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
4 changes: 1 addition & 3 deletions sjsonnet/src-js/sjsonnet/Platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ object Platform {
throw new Exception("hashFile not implemented in Scala.js")
}

private val regexCache = new util.LinkedHashMap[String, Pattern](100, 0.75f, true) {
override def removeEldestEntry(eldest: util.Map.Entry[String, Pattern]): Boolean = size() > 100
}
private val regexCache = new util.concurrent.ConcurrentHashMap[String, Pattern]
def getPatternFromCache(pat: String) : Pattern = regexCache.computeIfAbsent(pat, _ => Pattern.compile(pat))

def regexQuote(s: String): String = Pattern.quote(s)
Expand Down
4 changes: 1 addition & 3 deletions sjsonnet/src-jvm/sjsonnet/Platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ object Platform {
hash.getValue.toString
}

private val regexCache = new util.LinkedHashMap[String, Pattern](100, 0.75f, true) {
override def removeEldestEntry(eldest: util.Map.Entry[String, Pattern]): Boolean = size() > 100
}
private val regexCache = new util.concurrent.ConcurrentHashMap[String, Pattern]
def getPatternFromCache(pat: String) : Pattern = regexCache.computeIfAbsent(pat, _ => Pattern.compile(pat))

def regexQuote(s: String): String = Pattern.quote(s)
Expand Down
4 changes: 1 addition & 3 deletions sjsonnet/src-native/sjsonnet/Platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ object Platform {
scala.io.Source.fromFile(file).mkString
}

private val regexCache = new util.LinkedHashMap[String, Pattern](100, 0.75f, true) {
override def removeEldestEntry(eldest: util.Map.Entry[String, Pattern]): Boolean = size() > 100
}
private val regexCache = new util.concurrent.ConcurrentHashMap[String, Pattern]
def getPatternFromCache(pat: String) : Pattern = regexCache.computeIfAbsent(pat, _ => Pattern.compile(pat))

def regexQuote(s: String): String = Pattern.quote(s)
Expand Down

0 comments on commit aee46d2

Please sign in to comment.