Skip to content

Commit aaaf09f

Browse files
committed
Reuse already-computed index
1 parent 0c797a5 commit aaaf09f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/compiler/path.ts

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

460463
/**

0 commit comments

Comments
 (0)