Skip to content

Commit 14343be

Browse files
authored
Avoid calling replace in normalizeSlashes when it would do nothing (#44100)
* Make normalizeSlashes a no-op there are no bad slashes On Windows, there will probably be a negligible slowdown, iterating over the pre-slash prefix of each unnormalized path (though we might come out ahead if paths are normalized more than once). On *nix, this saves work - 1.8s -> 0.4s in the project I'm investigating. * Reuse already-computed index
1 parent 0864237 commit 14343be

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/compiler/path.ts

+5
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ namespace ts {
452452
* Normalize path separators, converting `\` into `/`.
453453
*/
454454
export function normalizeSlashes(path: string): string {
455+
const index = path.indexOf("\\");
456+
if (index === -1) {
457+
return path;
458+
}
459+
backslashRegExp.lastIndex = index; // prime regex with known position
455460
return path.replace(backslashRegExp, directorySeparator);
456461
}
457462

0 commit comments

Comments
 (0)