mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 11:35:42 -06:00
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
This commit is contained in:
parent
086423729a
commit
14343bead8
@ -452,6 +452,11 @@ namespace ts {
|
||||
* Normalize path separators, converting `\` into `/`.
|
||||
*/
|
||||
export function normalizeSlashes(path: string): string {
|
||||
const index = path.indexOf("\\");
|
||||
if (index === -1) {
|
||||
return path;
|
||||
}
|
||||
backslashRegExp.lastIndex = index; // prime regex with known position
|
||||
return path.replace(backslashRegExp, directorySeparator);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user