cache results of fileExists check in default compiler host

This commit is contained in:
Vladimir Matveev
2015-10-22 11:54:45 -07:00
parent ece96ac8a4
commit 6dda170e13

View File

@@ -209,6 +209,7 @@ namespace ts {
export function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost {
let currentDirectory: string;
let existingDirectories: Map<boolean> = {};
let existingFiles: Map<boolean> = {};
function getCanonicalFileName(fileName: string): string {
// if underlying system can distinguish between two files whose names differs only in cases then file name already in canonical form.
@@ -249,6 +250,14 @@ namespace ts {
return false;
}
function fileExists(fileName: string): boolean {
if (hasProperty(existingFiles, fileName)) {
return existingFiles[fileName];
}
return existingFiles[fileName] = sys.fileExists(fileName);
}
function ensureDirectoriesExist(directoryPath: string) {
if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) {
let parentDirectory = getDirectoryPath(directoryPath);
@@ -281,7 +290,7 @@ namespace ts {
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
getCanonicalFileName,
getNewLine: () => newLine,
fileExists: fileName => sys.fileExists(fileName),
fileExists,
readFile: fileName => sys.readFile(fileName)
};
}