Skip to content

Commit

Permalink
Switched to a standard map for LazyPlaceholderTranslationExpressionHa…
Browse files Browse the repository at this point in the history
…ndler
  • Loading branch information
WillFP committed Jul 5, 2023
1 parent 041fce6 commit 50f217e
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ class ImmediatePlaceholderTranslationExpressionHandler(
class LazyPlaceholderTranslationExpressionHandler(
private val placeholderParser: PlaceholderParser
) : ExpressionHandler {
private val cache: Cache<String, CompiledExpression?> = Caffeine.newBuilder()
.build()
private val cache = mutableMapOf<String, CompiledExpression?>()

override fun evaluate(expression: String, context: PlaceholderContext): Double? {
val placeholders = PlaceholderManager.findPlaceholdersIn(expression)
Expand All @@ -104,7 +103,7 @@ class LazyPlaceholderTranslationExpressionHandler(
.map { it.fastToDoubleOrNull() ?: 0.0 }
.toDoubleArray()

val compiled = cache.get(expression) {
val compiled = cache.getOrPut(expression) {
val env = EvaluationEnvironment()
env.setVariableNames(*placeholders.toTypedArray())
env.addFunctions(min, max)
Expand Down

0 comments on commit 50f217e

Please sign in to comment.