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:
parent
c228adc27d
commit
0b3968c468
1 changed files with 17 additions and 2 deletions
|
@ -526,12 +526,27 @@ const ESCAPE_ASCII_CHARS = [
|
||||||
["\v", "\\v"],
|
["\v", "\\v"],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} name
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
function escapeName(name) {
|
function escapeName(name) {
|
||||||
for (const [escape, replaceWith] of ESCAPE_ASCII_CHARS) {
|
// Check if we need to escape a character
|
||||||
name = StringPrototypeReplaceAll(name, escape, replaceWith);
|
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;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* id: number,
|
* id: number,
|
||||||
|
|
Loading…
Reference in a new issue