@@ -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
//
@@ -1630,12 +1631,12 @@ module ts {
1630
1631
// at each language service public entry point, since we don't know when
1631
1632
// set of scripts handled by the host changes.
1632
1633
class HostCache {
1633
- private fileNameToEntry : Map < HostFileInformation > ;
1634
+ private fileNameToEntry : FileMap < HostFileInformation > ;
1634
1635
private _compilationSettings : CompilerOptions ;
1635
1636
1636
- constructor ( private host : LanguageServiceHost , private getCanonicalFileName : ( fileName : string ) => string ) {
1637
+ constructor ( private host : LanguageServiceHost , getCanonicalFileName : ( fileName : string ) => string ) {
1637
1638
// script id => script index
1638
- this . fileNameToEntry = { } ;
1639
+ this . fileNameToEntry = createFileMap < HostFileInformation > ( getCanonicalFileName ) ;
1639
1640
1640
1641
// Initialize the list with the root file names
1641
1642
let rootFileNames = host . getScriptFileNames ( ) ;
@@ -1651,10 +1652,6 @@ module ts {
1651
1652
return this . _compilationSettings ;
1652
1653
}
1653
1654
1654
- private normalizeFileName ( fileName : string ) : string {
1655
- return this . getCanonicalFileName ( normalizeSlashes ( fileName ) ) ;
1656
- }
1657
-
1658
1655
private createEntry ( fileName : string ) {
1659
1656
let entry : HostFileInformation ;
1660
1657
let scriptSnapshot = this . host . getScriptSnapshot ( fileName ) ;
@@ -1666,15 +1663,16 @@ module ts {
1666
1663
} ;
1667
1664
}
1668
1665
1669
- return this . fileNameToEntry [ this . normalizeFileName ( fileName ) ] = entry ;
1666
+ this . fileNameToEntry . set ( fileName , entry ) ;
1667
+ return entry ;
1670
1668
}
1671
1669
1672
1670
private getEntry ( fileName : string ) : HostFileInformation {
1673
- return lookUp ( this . fileNameToEntry , this . normalizeFileName ( fileName ) ) ;
1671
+ return this . fileNameToEntry . get ( fileName ) ;
1674
1672
}
1675
1673
1676
1674
private contains ( fileName : string ) : boolean {
1677
- return hasProperty ( this . fileNameToEntry , this . normalizeFileName ( fileName ) ) ;
1675
+ return this . fileNameToEntry . contains ( fileName ) ;
1678
1676
}
1679
1677
1680
1678
public getOrCreateEntry ( fileName : string ) : HostFileInformation {
@@ -1688,10 +1686,9 @@ module ts {
1688
1686
public getRootFileNames ( ) : string [ ] {
1689
1687
let fileNames : string [ ] = [ ] ;
1690
1688
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 ) ;
1695
1692
}
1696
1693
} ) ;
1697
1694
@@ -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 . remove ( 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