1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -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"],
];
/**
* @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,