summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
authorMarvin Hagemeister <marvin@deno.com>2023-09-10 14:07:00 +0200
committerGitHub <noreply@github.com>2023-09-10 14:07:00 +0200
commit0b3968c468a4fb3ce97fdf74cb619e7c0922d372 (patch)
tree38cee8d07767837ef4d68c3099f7f2e8eb49e9d4 /cli/js
parentc228adc27d5b605286d3a9ca924e657308aebb74 (diff)
chore: speed up test name escapeing (#20439)
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/40_testing.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/cli/js/40_testing.js b/cli/js/40_testing.js
index 44b360a59..37eb6be8f 100644
--- a/cli/js/40_testing.js
+++ b/cli/js/40_testing.js
@@ -526,12 +526,27 @@ const ESCAPE_ASCII_CHARS = [
["\v", "\\v"],
];
+/**
+ * @param {string} name
+ * @returns {string}
+ */
function escapeName(name) {
- for (const [escape, replaceWith] of ESCAPE_ASCII_CHARS) {
- name = StringPrototypeReplaceAll(name, escape, replaceWith);
+ // Check if we need to escape a character
+ for (let i = 0; i < name.length; i++) {
+ const ch = name.charCodeAt(i);
+ if (ch <= 13 && ch >= 8) {
+ // Slow path: We do need to escape it
+ for (const [escape, replaceWith] of ESCAPE_ASCII_CHARS) {
+ name = StringPrototypeReplaceAll(name, escape, replaceWith);
+ }
+ return name;
+ }
}
+
+ // We didn't need to escape anything, return original string
return name;
}
+
/**
* @typedef {{
* id: number,