1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-31 11:34:15 -05:00

chore: speed up test name escapeing (#20439)

This commit is contained in:
Marvin Hagemeister 2023-09-10 14:07:00 +02:00 committed by GitHub
parent c228adc27d
commit 0b3968c468
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -526,12 +526,27 @@ const ESCAPE_ASCII_CHARS = [
["\v", "\\v"], ["\v", "\\v"],
]; ];
/**
* @param {string} name
* @returns {string}
*/
function escapeName(name) { function escapeName(name) {
// 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) { for (const [escape, replaceWith] of ESCAPE_ASCII_CHARS) {
name = StringPrototypeReplaceAll(name, escape, replaceWith); name = StringPrototypeReplaceAll(name, escape, replaceWith);
} }
return name; return name;
} }
}
// We didn't need to escape anything, return original string
return name;
}
/** /**
* @typedef {{ * @typedef {{
* id: number, * id: number,