From 671a7644640943918fe2bc0223146b76e146dc33 Mon Sep 17 00:00:00 2001 From: Stephen Amar Date: Sat, 28 Dec 2024 20:00:19 -0800 Subject: [PATCH] Fix performance regression in stripChars --- sjsonnet/src/sjsonnet/Std.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sjsonnet/src/sjsonnet/Std.scala b/sjsonnet/src/sjsonnet/Std.scala index 0322be98..23383e9b 100644 --- a/sjsonnet/src/sjsonnet/Std.scala +++ b/sjsonnet/src/sjsonnet/Std.scala @@ -499,13 +499,13 @@ class Std(private val additionalNativeFunctions: Map[String, Val.Builtin] = Map. right: Boolean, functionName: String ) extends Val.Builtin1(functionName, "str") { - private[this] val leftPattern = getLeadingPattern(chars) - private[this] val rightPattern = getTrailingPattern(chars) + private[this] val leftPattern = Platform.getPatternFromCache(getLeadingPattern(chars)) + private[this] val rightPattern = Platform.getPatternFromCache(getTrailingPattern(chars)) def evalRhs(str: Val, ev: EvalScope, pos: Position): Val = { var s = str.asString - if (right) s = Platform.getPatternFromCache(rightPattern).matcher(s).replaceAll("") - if (left) s = Platform.getPatternFromCache(leftPattern).matcher(s).replaceAll("") + if (right) s = rightPattern.matcher(s).replaceAll("") + if (left) s = leftPattern.matcher(s).replaceAll("") Val.Str(pos, s) } }