Skip to content

Commit e0d407b

Browse files
Only start building up a replacement normalized string when needed.
1 parent 4990bd9 commit e0d407b

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/compiler/path.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace ts {
88
export const directorySeparator = "/";
99
export const altDirectorySeparator = "\\";
1010
const urlSchemeSeparator = "://";
11-
const backslashRegExp = /\\/g;
1211

1312
//// Path Tests
1413

@@ -452,7 +451,20 @@ namespace ts {
452451
* Normalize path separators, converting `\` into `/`.
453452
*/
454453
export function normalizeSlashes(path: string): string {
455-
return path.replace(backslashRegExp, directorySeparator);
454+
let lastSliceStart = 0;
455+
let segments: string[] | undefined;
456+
for (let i = 0; i < path.length; i++) {
457+
const c = path.charCodeAt(i);
458+
if (c === CharacterCodes.backslash) {
459+
(segments ||= []).push(path.slice(lastSliceStart, i));
460+
lastSliceStart = i + 1;
461+
}
462+
}
463+
if (segments) {
464+
segments.push(path.slice(lastSliceStart));
465+
return segments.join(directorySeparator);
466+
}
467+
return path;
456468
}
457469

458470
/**

0 commit comments

Comments
 (0)