Skip to content

Commit e8e278e

Browse files
itchynyjohnbartholomew
authored andcommitted
Improve performance of escapeStringBash and escapeStringDollars
1 parent 67a4421 commit e8e278e

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

stdlib/std.jsonnet

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,21 +1018,11 @@ limitations under the License.
10181018

10191019
escapeStringBash(str_)::
10201020
local str = std.toString(str_);
1021-
local trans(ch) =
1022-
if ch == "'" then
1023-
"'\"'\"'"
1024-
else
1025-
ch;
1026-
"'%s'" % std.join('', [trans(ch) for ch in std.stringChars(str)]),
1021+
"'%s'" % std.strReplace(str, "'", "'\"'\"'"),
10271022

10281023
escapeStringDollars(str_)::
10291024
local str = std.toString(str_);
1030-
local trans(ch) =
1031-
if ch == '$' then
1032-
'$$'
1033-
else
1034-
ch;
1035-
std.foldl(function(a, b) a + trans(b), std.stringChars(str), ''),
1025+
std.strReplace(str, '$', '$$'),
10361026

10371027
local xml_escapes = {
10381028
'<': '&lt;',

0 commit comments

Comments
 (0)