Skip to content

Commit 7954f0c

Browse files
authored
Kick out of normalizePath if there's nothing to do (microsoft#44173)
* Kick out of normalizePath if there's nothing to do ...using `relativePathSegmentRegExp`. Bonus: use a regex to handle "/./" to avoid splitting and joining in a common case. When building the compiler, for example, it looks like ~95% of arguments to `normalizePath` do not require any normalization. * Check normalization before and after . cleanup * Also cleanup leading ./
1 parent eb7c1ad commit 7954f0c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/compiler/path.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,19 @@ namespace ts {
552552

553553
export function normalizePath(path: string): string {
554554
path = normalizeSlashes(path);
555+
// Most paths don't require normalization
556+
if (!relativePathSegmentRegExp.test(path)) {
557+
return path;
558+
}
559+
// Some paths only require cleanup of `/./` or leading `./`
560+
const simplified = path.replace(/\/\.\//g, "/").replace(/^\.\//, "");
561+
if (simplified !== path) {
562+
path = simplified;
563+
if (!relativePathSegmentRegExp.test(path)) {
564+
return path;
565+
}
566+
}
567+
// Other paths require full normalization
555568
const normalized = getPathFromPathComponents(reducePathComponents(getPathComponents(path)));
556569
return normalized && hasTrailingDirectorySeparator(path) ? ensureTrailingDirectorySeparator(normalized) : normalized;
557570
}

0 commit comments

Comments
 (0)