@@ -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 //
@@ -1632,12 +1633,12 @@ module ts {
16321633 // at each language service public entry point, since we don't know when
16331634 // set of scripts handled by the host changes.
16341635 class HostCache {
1635- private fileNameToEntry : Map < HostFileInformation > ;
1636+ private fileNameToEntry : FileMap < HostFileInformation > ;
16361637 private _compilationSettings : CompilerOptions ;
16371638
1638- constructor ( private host : LanguageServiceHost , private getCanonicalFileName : ( fileName : string ) => string ) {
1639+ constructor ( private host : LanguageServiceHost , getCanonicalFileName : ( fileName : string ) => string ) {
16391640 // script id => script index
1640- this . fileNameToEntry = { } ;
1641+ this . fileNameToEntry = new FileMap < HostFileInformation > ( getCanonicalFileName ) ;
16411642
16421643 // Initialize the list with the root file names
16431644 let rootFileNames = host . getScriptFileNames ( ) ;
@@ -1653,10 +1654,6 @@ module ts {
16531654 return this . _compilationSettings ;
16541655 }
16551656
1656- private normalizeFileName ( fileName : string ) : string {
1657- return this . getCanonicalFileName ( normalizeSlashes ( fileName ) ) ;
1658- }
1659-
16601657 private createEntry ( fileName : string ) {
16611658 let entry : HostFileInformation ;
16621659 let scriptSnapshot = this . host . getScriptSnapshot ( fileName ) ;
@@ -1668,15 +1665,16 @@ module ts {
16681665 } ;
16691666 }
16701667
1671- return this . fileNameToEntry [ this . normalizeFileName ( fileName ) ] = entry ;
1668+ this . fileNameToEntry . set ( fileName , entry ) ;
1669+ return entry ;
16721670 }
16731671
16741672 private getEntry ( fileName : string ) : HostFileInformation {
1675- return lookUp ( this . fileNameToEntry , this . normalizeFileName ( fileName ) ) ;
1673+ return this . fileNameToEntry . get ( fileName ) ;
16761674 }
16771675
16781676 private contains ( fileName : string ) : boolean {
1679- return hasProperty ( this . fileNameToEntry , this . normalizeFileName ( fileName ) ) ;
1677+ return this . fileNameToEntry . contains ( fileName ) ;
16801678 }
16811679
16821680 public getOrCreateEntry ( fileName : string ) : HostFileInformation {
@@ -1690,10 +1688,9 @@ module ts {
16901688 public getRootFileNames ( ) : string [ ] {
16911689 let fileNames : string [ ] = [ ] ;
16921690
1693- forEachKey ( this . fileNameToEntry , key => {
1694- let entry = this . getEntry ( key ) ;
1695- if ( entry ) {
1696- fileNames . push ( entry . hostFileName ) ;
1691+ this . fileNameToEntry . forEachValue ( value => {
1692+ if ( value ) {
1693+ fileNames . push ( value . hostFileName ) ;
16971694 }
16981695 } ) ;
16991696
@@ -1873,20 +1870,28 @@ module ts {
18731870 return createLanguageServiceSourceFile ( sourceFile . fileName , scriptSnapshot , sourceFile . languageVersion , version , /*setNodeParents:*/ true ) ;
18741871 }
18751872
1876- export function createDocumentRegistry ( ) : DocumentRegistry {
1873+ function createGetCanonicalFileName ( useCaseSensitivefileNames : boolean ) : ( fileName : string ) => string {
1874+ return useCaseSensitivefileNames
1875+ ? ( ( fileName ) => fileName )
1876+ : ( ( fileName ) => fileName . toLowerCase ( ) ) ;
1877+ }
1878+
1879+
1880+ export function createDocumentRegistry ( useCaseSensitiveFileNames ?: boolean ) : DocumentRegistry {
18771881 // Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have
18781882 // for those settings.
1879- let buckets : Map < Map < DocumentRegistryEntry > > = { } ;
1883+ let buckets : Map < FileMap < DocumentRegistryEntry > > = { } ;
1884+ let getCanonicalFileName = createGetCanonicalFileName ( useCaseSensitiveFileNames || false ) ;
18801885
18811886 function getKeyFromCompilationSettings ( settings : CompilerOptions ) : string {
18821887 return "_" + settings . target ; // + "|" + settings.propagateEnumConstantoString()
18831888 }
18841889
1885- function getBucketForCompilationSettings ( settings : CompilerOptions , createIfMissing : boolean ) : Map < DocumentRegistryEntry > {
1890+ function getBucketForCompilationSettings ( settings : CompilerOptions , createIfMissing : boolean ) : FileMap < DocumentRegistryEntry > {
18861891 let key = getKeyFromCompilationSettings ( settings ) ;
18871892 let bucket = lookUp ( buckets , key ) ;
18881893 if ( ! bucket && createIfMissing ) {
1889- buckets [ key ] = bucket = { } ;
1894+ buckets [ key ] = bucket = new FileMap < DocumentRegistryEntry > ( getCanonicalFileName ) ;
18901895 }
18911896 return bucket ;
18921897 }
@@ -1896,7 +1901,7 @@ module ts {
18961901 let entries = lookUp ( buckets , name ) ;
18971902 let sourceFiles : { name : string ; refCount : number ; references : string [ ] ; } [ ] = [ ] ;
18981903 for ( let i in entries ) {
1899- let entry = entries [ i ] ;
1904+ let entry = entries . get ( i ) ;
19001905 sourceFiles . push ( {
19011906 name : i ,
19021907 refCount : entry . languageServiceRefCount ,
@@ -1928,18 +1933,19 @@ module ts {
19281933 acquiring : boolean ) : SourceFile {
19291934
19301935 let bucket = getBucketForCompilationSettings ( compilationSettings , /*createIfMissing*/ true ) ;
1931- let entry = lookUp ( bucket , fileName ) ;
1936+ let entry = bucket . get ( fileName ) ;
19321937 if ( ! entry ) {
19331938 Debug . assert ( acquiring , "How could we be trying to update a document that the registry doesn't have?" ) ;
19341939
19351940 // Have never seen this file with these settings. Create a new source file for it.
19361941 let sourceFile = createLanguageServiceSourceFile ( fileName , scriptSnapshot , compilationSettings . target , version , /*setNodeParents:*/ false ) ;
19371942
1938- bucket [ fileName ] = entry = {
1943+ entry = {
19391944 sourceFile : sourceFile ,
19401945 languageServiceRefCount : 0 ,
19411946 owners : [ ]
19421947 } ;
1948+ bucket . set ( fileName , entry ) ;
19431949 }
19441950 else {
19451951 // We have an entry for this file. However, it may be for a different version of
@@ -1967,12 +1973,12 @@ module ts {
19671973 let bucket = getBucketForCompilationSettings ( compilationSettings , false ) ;
19681974 Debug . assert ( bucket !== undefined ) ;
19691975
1970- let entry = lookUp ( bucket , fileName ) ;
1976+ let entry = bucket . get ( fileName ) ;
19711977 entry . languageServiceRefCount -- ;
19721978
19731979 Debug . assert ( entry . languageServiceRefCount >= 0 ) ;
19741980 if ( entry . languageServiceRefCount === 0 ) {
1975- delete bucket [ fileName ] ;
1981+ bucket . delete ( fileName ) ;
19761982 }
19771983 }
19781984
@@ -2400,9 +2406,7 @@ module ts {
24002406 }
24012407 }
24022408
2403- function getCanonicalFileName ( fileName : string ) {
2404- return useCaseSensitivefileNames ? fileName : fileName . toLowerCase ( ) ;
2405- }
2409+ let getCanonicalFileName = createGetCanonicalFileName ( useCaseSensitivefileNames ) ;
24062410
24072411 function getValidSourceFile ( fileName : string ) : SourceFile {
24082412 fileName = normalizeSlashes ( fileName ) ;
0 commit comments