Skip to content

Commit eb31544

Browse files
scr-oathsparkprime
authored andcommitted
In case escapeStringXML is invoked many times, move the escapes out to local var.
1 parent 7361bfe commit eb31544

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

stdlib/std.jsonnet

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,16 +1012,17 @@ limitations under the License.
10121012
ch;
10131013
std.foldl(function(a, b) a + trans(b), std.stringChars(str), ''),
10141014

1015+
local xml_escapes = {
1016+
'<': '&lt;',
1017+
'>': '&gt;',
1018+
'&': '&amp;',
1019+
'"': '&quot;',
1020+
"'": '&apos;',
1021+
},
1022+
10151023
escapeStringXML(str_)::
10161024
local str = std.toString(str_);
1017-
local escapes = {
1018-
'<': '&lt;',
1019-
'>': '&gt;',
1020-
'&': '&amp;',
1021-
'"': '&quot;',
1022-
"'": '&apos;',
1023-
};
1024-
std.join('', [std.get(escapes, ch, ch) for ch in std.stringChars(str)]),
1025+
std.join('', [std.get(xml_escapes, ch, ch) for ch in std.stringChars(str)]),
10251026

10261027
manifestJson(value):: std.manifestJsonEx(value, ' '),
10271028

0 commit comments

Comments
 (0)