Skip to content

Commit

Permalink
Fix performance regression in stripChars
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenamar-db committed Dec 29, 2024
1 parent aee46d2 commit 671a764
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sjsonnet/src/sjsonnet/Std.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 671a764

Please sign in to comment.