@@ -960,6 +960,7 @@ module ts {
960960 log ? ( s : string ) : void ;
961961 trace ? ( s : string ) : void ;
962962 error ? ( s : string ) : void ;
963+ useCaseSensitiveFileNames ? ( ) : boolean ;
963964 }
964965
965966 //
@@ -1630,12 +1631,12 @@ module ts {
16301631 // at each language service public entry point, since we don't know when
16311632 // set of scripts handled by the host changes.
16321633 class HostCache {
1633- private fileNameToEntry : Map < HostFileInformation > ;
1634+ private fileNameToEntry : FileMap < HostFileInformation > ;
16341635 private _compilationSettings : CompilerOptions ;
16351636
1636- constructor ( private host : LanguageServiceHost , private getCanonicalFileName : ( fileName : string ) => string ) {
1637+ constructor ( private host : LanguageServiceHost , getCanonicalFileName : ( fileName : string ) => string ) {
16371638 // script id => script index
1638- this . fileNameToEntry = { } ;
1639+ this . fileNameToEntry = createFileMap < HostFileInformation > ( getCanonicalFileName ) ;
16391640
16401641 // Initialize the list with the root file names
16411642 let rootFileNames = host . getScriptFileNames ( ) ;
@@ -1651,10 +1652,6 @@ module ts {
16511652 return this . _compilationSettings ;
16521653 }
16531654
1654- private normalizeFileName ( fileName : string ) : string {
1655- return this . getCanonicalFileName ( normalizeSlashes ( fileName ) ) ;
1656- }
1657-
16581655 private createEntry ( fileName : string ) {
16591656 let entry : HostFileInformation ;
16601657 let scriptSnapshot = this . host . getScriptSnapshot ( fileName ) ;
@@ -1666,15 +1663,16 @@ module ts {
16661663 } ;
16671664 }
16681665
1669- return this . fileNameToEntry [ this . normalizeFileName ( fileName ) ] = entry ;
1666+ this . fileNameToEntry . set ( fileName , entry ) ;
1667+ return entry ;
16701668 }
16711669
16721670 private getEntry ( fileName : string ) : HostFileInformation {
1673- return lookUp ( this . fileNameToEntry , this . normalizeFileName ( fileName ) ) ;
1671+ return this . fileNameToEntry . get ( fileName ) ;
16741672 }
16751673
16761674 private contains ( fileName : string ) : boolean {
1677- return hasProperty ( this . fileNameToEntry , this . normalizeFileName ( fileName ) ) ;
1675+ return this . fileNameToEntry . contains ( fileName ) ;
16781676 }
16791677
16801678 public getOrCreateEntry ( fileName : string ) : HostFileInformation {
@@ -1688,10 +1686,9 @@ module ts {
16881686 public getRootFileNames ( ) : string [ ] {
16891687 let fileNames : string [ ] = [ ] ;
16901688
1691- forEachKey ( this . fileNameToEntry , key => {
1692- let entry = this . getEntry ( key ) ;
1693- if ( entry ) {
1694- fileNames . push ( entry . hostFileName ) ;
1689+ this . fileNameToEntry . forEachValue ( value => {
1690+ if ( value ) {
1691+ fileNames . push ( value . hostFileName ) ;
16951692 }
16961693 } ) ;
16971694
@@ -1885,20 +1882,28 @@ module ts {
18851882 return createLanguageServiceSourceFile ( sourceFile . fileName , scriptSnapshot , sourceFile . languageVersion , version , /*setNodeParents:*/ true ) ;
18861883 }
18871884
1888- export function createDocumentRegistry ( ) : DocumentRegistry {
1885+ function createGetCanonicalFileName ( useCaseSensitivefileNames : boolean ) : ( fileName : string ) => string {
1886+ return useCaseSensitivefileNames
1887+ ? ( ( fileName ) => fileName )
1888+ : ( ( fileName ) => fileName . toLowerCase ( ) ) ;
1889+ }
1890+
1891+
1892+ export function createDocumentRegistry ( useCaseSensitiveFileNames ?: boolean ) : DocumentRegistry {
18891893 // Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have
18901894 // for those settings.
1891- let buckets : Map < Map < DocumentRegistryEntry > > = { } ;
1895+ let buckets : Map < FileMap < DocumentRegistryEntry > > = { } ;
1896+ let getCanonicalFileName = createGetCanonicalFileName ( ! ! useCaseSensitiveFileNames ) ;
18921897
18931898 function getKeyFromCompilationSettings ( settings : CompilerOptions ) : string {
18941899 return "_" + settings . target ; // + "|" + settings.propagateEnumConstantoString()
18951900 }
18961901
1897- function getBucketForCompilationSettings ( settings : CompilerOptions , createIfMissing : boolean ) : Map < DocumentRegistryEntry > {
1902+ function getBucketForCompilationSettings ( settings : CompilerOptions , createIfMissing : boolean ) : FileMap < DocumentRegistryEntry > {
18981903 let key = getKeyFromCompilationSettings ( settings ) ;
18991904 let bucket = lookUp ( buckets , key ) ;
19001905 if ( ! bucket && createIfMissing ) {
1901- buckets [ key ] = bucket = { } ;
1906+ buckets [ key ] = bucket = createFileMap < DocumentRegistryEntry > ( getCanonicalFileName ) ;
19021907 }
19031908 return bucket ;
19041909 }
@@ -1908,7 +1913,7 @@ module ts {
19081913 let entries = lookUp ( buckets , name ) ;
19091914 let sourceFiles : { name : string ; refCount : number ; references : string [ ] ; } [ ] = [ ] ;
19101915 for ( let i in entries ) {
1911- let entry = entries [ i ] ;
1916+ let entry = entries . get ( i ) ;
19121917 sourceFiles . push ( {
19131918 name : i ,
19141919 refCount : entry . languageServiceRefCount ,
@@ -1940,18 +1945,19 @@ module ts {
19401945 acquiring : boolean ) : SourceFile {
19411946
19421947 let bucket = getBucketForCompilationSettings ( compilationSettings , /*createIfMissing*/ true ) ;
1943- let entry = lookUp ( bucket , fileName ) ;
1948+ let entry = bucket . get ( fileName ) ;
19441949 if ( ! entry ) {
19451950 Debug . assert ( acquiring , "How could we be trying to update a document that the registry doesn't have?" ) ;
19461951
19471952 // Have never seen this file with these settings. Create a new source file for it.
19481953 let sourceFile = createLanguageServiceSourceFile ( fileName , scriptSnapshot , compilationSettings . target , version , /*setNodeParents:*/ false ) ;
19491954
1950- bucket [ fileName ] = entry = {
1955+ entry = {
19511956 sourceFile : sourceFile ,
19521957 languageServiceRefCount : 0 ,
19531958 owners : [ ]
19541959 } ;
1960+ bucket . set ( fileName , entry ) ;
19551961 }
19561962 else {
19571963 // We have an entry for this file. However, it may be for a different version of
@@ -1979,12 +1985,12 @@ module ts {
19791985 let bucket = getBucketForCompilationSettings ( compilationSettings , false ) ;
19801986 Debug . assert ( bucket !== undefined ) ;
19811987
1982- let entry = lookUp ( bucket , fileName ) ;
1988+ let entry = bucket . get ( fileName ) ;
19831989 entry . languageServiceRefCount -- ;
19841990
19851991 Debug . assert ( entry . languageServiceRefCount >= 0 ) ;
19861992 if ( entry . languageServiceRefCount === 0 ) {
1987- delete bucket [ fileName ] ;
1993+ bucket . remove ( fileName ) ;
19881994 }
19891995 }
19901996
@@ -2412,9 +2418,7 @@ module ts {
24122418 }
24132419 }
24142420
2415- function getCanonicalFileName ( fileName : string ) {
2416- return useCaseSensitivefileNames ? fileName : fileName . toLowerCase ( ) ;
2417- }
2421+ let getCanonicalFileName = createGetCanonicalFileName ( useCaseSensitivefileNames ) ;
24182422
24192423 function getValidSourceFile ( fileName : string ) : SourceFile {
24202424 fileName = normalizeSlashes ( fileName ) ;
0 commit comments