From 9d58b5782f0673276bf36f772ef052e021cdfb62 Mon Sep 17 00:00:00 2001 From: itchyny Date: Mon, 8 Apr 2024 20:26:26 +0900 Subject: [PATCH] Improve performance of escapeStringBash and escapeStringDollars --- stdlib/std.jsonnet | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/stdlib/std.jsonnet b/stdlib/std.jsonnet index a843d3a08..b305f0d76 100644 --- a/stdlib/std.jsonnet +++ b/stdlib/std.jsonnet @@ -1005,21 +1005,11 @@ limitations under the License. escapeStringBash(str_):: local str = std.toString(str_); - local trans(ch) = - if ch == "'" then - "'\"'\"'" - else - ch; - "'%s'" % std.join('', [trans(ch) for ch in std.stringChars(str)]), + "'%s'" % std.strReplace(str, "'", "'\"'\"'"), escapeStringDollars(str_):: local str = std.toString(str_); - local trans(ch) = - if ch == '$' then - '$$' - else - ch; - std.foldl(function(a, b) a + trans(b), std.stringChars(str), ''), + std.strReplace(str, '$', '$$'), local xml_escapes = { '<': '<',