diff options
author | Marvin Hagemeister <marvin@deno.com> | 2023-09-10 14:07:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-10 14:07:00 +0200 |
commit | 0b3968c468a4fb3ce97fdf74cb619e7c0922d372 (patch) | |
tree | 38cee8d07767837ef4d68c3099f7f2e8eb49e9d4 /cli/js | |
parent | c228adc27d5b605286d3a9ca924e657308aebb74 (diff) |
chore: speed up test name escapeing (#20439)
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/40_testing.js | 19 |
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, |