From 6dda170e13b7fc4edb4c05b0048cf6e5fe52da55 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 22 Oct 2015 11:54:45 -0700 Subject: [PATCH] cache results of fileExists check in default compiler host --- src/compiler/program.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index d76e7585d15..85a43ac537f 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -209,6 +209,7 @@ namespace ts { export function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost { let currentDirectory: string; let existingDirectories: Map = {}; + let existingFiles: Map = {}; 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) }; }