Skip to content

Commit e101c10

Browse files
Move to concurrenthashmap for the pattern cache
1 parent 39c7bce commit e101c10

3 files changed

Lines changed: 3 additions & 9 deletions

File tree

sjsonnet/src-js/sjsonnet/Platform.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ object Platform {
4040
throw new Exception("hashFile not implemented in Scala.js")
4141
}
4242

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

4846
def regexQuote(s: String): String = Pattern.quote(s)

sjsonnet/src-jvm/sjsonnet/Platform.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ object Platform {
111111
hash.getValue.toString
112112
}
113113

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

119117
def regexQuote(s: String): String = Pattern.quote(s)

sjsonnet/src-native/sjsonnet/Platform.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ object Platform {
5353
scala.io.Source.fromFile(file).mkString
5454
}
5555

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

6159
def regexQuote(s: String): String = Pattern.quote(s)

0 commit comments

Comments
 (0)