@@ -960,6 +960,7 @@ module ts {
960
960
log ? ( s : string ) : void ;
961
961
trace ? ( s : string ) : void ;
962
962
error ? ( s : string ) : void ;
963
+ useCaseSensitiveFileNames ? ( ) : boolean ;
963
964
}
964
965
965
966
//
@@ -1632,12 +1633,12 @@ module ts {
1632
1633
// at each language service public entry point, since we don't know when
1633
1634
// set of scripts handled by the host changes.
1634
1635
class HostCache {
1635
- private fileNameToEntry : Map < HostFileInformation > ;
1636
+ private fileNameToEntry : FileMap < HostFileInformation > ;
1636
1637
private _compilationSettings : CompilerOptions ;
1637
1638
1638
- constructor ( private host : LanguageServiceHost , private getCanonicalFileName : ( fileName : string ) => string ) {
1639
+ constructor ( private host : LanguageServiceHost , getCanonicalFileName : ( fileName : string ) => string ) {
1639
1640
// script id => script index
1640
- this . fileNameToEntry = { } ;
1641
+ this . fileNameToEntry = createFileMap < HostFileInformation > ( getCanonicalFileName ) ;
1641
1642
1642
1643
// Initialize the list with the root file names
1643
1644
let rootFileNames = host . getScriptFileNames ( ) ;
@@ -1653,10 +1654,6 @@ module ts {
1653
1654
return this . _compilationSettings ;
1654
1655
}
1655
1656
1656
- private normalizeFileName ( fileName : string ) : string {
1657
- return this . getCanonicalFileName ( normalizeSlashes ( fileName ) ) ;
1658
- }
1659
-
1660
1657
private createEntry ( fileName : string ) {
1661
1658
let entry : HostFileInformation ;
1662
1659
let scriptSnapshot = this . host . getScriptSnapshot ( fileName ) ;
@@ -1668,15 +1665,16 @@ module ts {
1668
1665
} ;
1669
1666
}
1670
1667
1671
- return this . fileNameToEntry [ this . normalizeFileName ( fileName ) ] = entry ;
1668
+ this . fileNameToEntry . set ( fileName , entry ) ;
1669
+ return entry ;
1672
1670
}
1673
1671
1674
1672
private getEntry ( fileName : string ) : HostFileInformation {
1675
- return lookUp ( this . fileNameToEntry , this . normalizeFileName ( fileName ) ) ;
1673
+ return this . fileNameToEntry . get ( fileName ) ;
1676
1674
}
1677
1675
1678
1676
private contains ( fileName : string ) : boolean {
1679
- return hasProperty ( this . fileNameToEntry , this . normalizeFileName ( fileName ) ) ;
1677
+ return this . fileNameToEntry . contains ( fileName ) ;
1680
1678
}
1681
1679
1682
1680
public getOrCreateEntry ( fileName : string ) : HostFileInformation {
@@ -1690,10 +1688,9 @@ module ts {
1690
1688
public getRootFileNames ( ) : string [ ] {
1691
1689
let fileNames : string [ ] = [ ] ;
1692
1690
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 ) ;
1697
1694
}
1698
1695
} ) ;
1699
1696
@@ -1885,20 +1882,28 @@ module ts {
1885
1882
return createLanguageServiceSourceFile ( sourceFile . fileName , scriptSnapshot , sourceFile . languageVersion , version , /*setNodeParents:*/ true ) ;
1886
1883
}
1887
1884
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 {
1889
1893
// Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have
1890
1894
// for those settings.
1891
- let buckets : Map < Map < DocumentRegistryEntry > > = { } ;
1895
+ let buckets : Map < FileMap < DocumentRegistryEntry > > = { } ;
1896
+ let getCanonicalFileName = createGetCanonicalFileName ( ! ! useCaseSensitiveFileNames ) ;
1892
1897
1893
1898
function getKeyFromCompilationSettings ( settings : CompilerOptions ) : string {
1894
1899
return "_" + settings . target ; // + "|" + settings.propagateEnumConstantoString()
1895
1900
}
1896
1901
1897
- function getBucketForCompilationSettings ( settings : CompilerOptions , createIfMissing : boolean ) : Map < DocumentRegistryEntry > {
1902
+ function getBucketForCompilationSettings ( settings : CompilerOptions , createIfMissing : boolean ) : FileMap < DocumentRegistryEntry > {
1898
1903
let key = getKeyFromCompilationSettings ( settings ) ;
1899
1904
let bucket = lookUp ( buckets , key ) ;
1900
1905
if ( ! bucket && createIfMissing ) {
1901
- buckets [ key ] = bucket = { } ;
1906
+ buckets [ key ] = bucket = createFileMap < DocumentRegistryEntry > ( getCanonicalFileName ) ;
1902
1907
}
1903
1908
return bucket ;
1904
1909
}
@@ -1908,7 +1913,7 @@ module ts {
1908
1913
let entries = lookUp ( buckets , name ) ;
1909
1914
let sourceFiles : { name : string ; refCount : number ; references : string [ ] ; } [ ] = [ ] ;
1910
1915
for ( let i in entries ) {
1911
- let entry = entries [ i ] ;
1916
+ let entry = entries . get ( i ) ;
1912
1917
sourceFiles . push ( {
1913
1918
name : i ,
1914
1919
refCount : entry . languageServiceRefCount ,
@@ -1940,18 +1945,19 @@ module ts {
1940
1945
acquiring : boolean ) : SourceFile {
1941
1946
1942
1947
let bucket = getBucketForCompilationSettings ( compilationSettings , /*createIfMissing*/ true ) ;
1943
- let entry = lookUp ( bucket , fileName ) ;
1948
+ let entry = bucket . get ( fileName ) ;
1944
1949
if ( ! entry ) {
1945
1950
Debug . assert ( acquiring , "How could we be trying to update a document that the registry doesn't have?" ) ;
1946
1951
1947
1952
// Have never seen this file with these settings. Create a new source file for it.
1948
1953
let sourceFile = createLanguageServiceSourceFile ( fileName , scriptSnapshot , compilationSettings . target , version , /*setNodeParents:*/ false ) ;
1949
1954
1950
- bucket [ fileName ] = entry = {
1955
+ entry = {
1951
1956
sourceFile : sourceFile ,
1952
1957
languageServiceRefCount : 0 ,
1953
1958
owners : [ ]
1954
1959
} ;
1960
+ bucket . set ( fileName , entry ) ;
1955
1961
}
1956
1962
else {
1957
1963
// We have an entry for this file. However, it may be for a different version of
@@ -1979,12 +1985,12 @@ module ts {
1979
1985
let bucket = getBucketForCompilationSettings ( compilationSettings , false ) ;
1980
1986
Debug . assert ( bucket !== undefined ) ;
1981
1987
1982
- let entry = lookUp ( bucket , fileName ) ;
1988
+ let entry = bucket . get ( fileName ) ;
1983
1989
entry . languageServiceRefCount -- ;
1984
1990
1985
1991
Debug . assert ( entry . languageServiceRefCount >= 0 ) ;
1986
1992
if ( entry . languageServiceRefCount === 0 ) {
1987
- delete bucket [ fileName ] ;
1993
+ bucket . delete ( fileName ) ;
1988
1994
}
1989
1995
}
1990
1996
@@ -2412,9 +2418,7 @@ module ts {
2412
2418
}
2413
2419
}
2414
2420
2415
- function getCanonicalFileName ( fileName : string ) {
2416
- return useCaseSensitivefileNames ? fileName : fileName . toLowerCase ( ) ;
2417
- }
2421
+ let getCanonicalFileName = createGetCanonicalFileName ( useCaseSensitivefileNames ) ;
2418
2422
2419
2423
function getValidSourceFile ( fileName : string ) : SourceFile {
2420
2424
fileName = normalizeSlashes ( fileName ) ;
0 commit comments