Skip to content

Commit f040500

Browse files
Try to reuse the same array over and over.
1 parent e0d407b commit f040500

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/compiler/path.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,22 +447,23 @@ namespace ts {
447447

448448
//// Path Normalization
449449

450+
const normalizeSlashesSegmentBuffer: string[] = [];
450451
/**
451452
* Normalize path separators, converting `\` into `/`.
452453
*/
453454
export function normalizeSlashes(path: string): string {
455+
normalizeSlashesSegmentBuffer.length = 0;
454456
let lastSliceStart = 0;
455-
let segments: string[] | undefined;
456457
for (let i = 0; i < path.length; i++) {
457458
const c = path.charCodeAt(i);
458459
if (c === CharacterCodes.backslash) {
459-
(segments ||= []).push(path.slice(lastSliceStart, i));
460+
normalizeSlashesSegmentBuffer.push(path.slice(lastSliceStart, i));
460461
lastSliceStart = i + 1;
461462
}
462463
}
463-
if (segments) {
464-
segments.push(path.slice(lastSliceStart));
465-
return segments.join(directorySeparator);
464+
if (normalizeSlashesSegmentBuffer.length > 0) {
465+
normalizeSlashesSegmentBuffer.push(path.slice(lastSliceStart));
466+
return normalizeSlashesSegmentBuffer.join(directorySeparator);
466467
}
467468
return path;
468469
}

0 commit comments

Comments
 (0)