@@ -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 = new FileMap < 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
@@ -1873,20 +1870,28 @@ module ts {
1873
1870
return createLanguageServiceSourceFile ( sourceFile . fileName , scriptSnapshot , sourceFile . languageVersion , version , /*setNodeParents:*/ true ) ;
1874
1871
}
1875
1872
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 {
1877
1881
// Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have
1878
1882
// for those settings.
1879
- let buckets : Map < Map < DocumentRegistryEntry > > = { } ;
1883
+ let buckets : Map < FileMap < DocumentRegistryEntry > > = { } ;
1884
+ let getCanonicalFileName = createGetCanonicalFileName ( useCaseSensitiveFileNames || false ) ;
1880
1885
1881
1886
function getKeyFromCompilationSettings ( settings : CompilerOptions ) : string {
1882
1887
return "_" + settings . target ; // + "|" + settings.propagateEnumConstantoString()
1883
1888
}
1884
1889
1885
- function getBucketForCompilationSettings ( settings : CompilerOptions , createIfMissing : boolean ) : Map < DocumentRegistryEntry > {
1890
+ function getBucketForCompilationSettings ( settings : CompilerOptions , createIfMissing : boolean ) : FileMap < DocumentRegistryEntry > {
1886
1891
let key = getKeyFromCompilationSettings ( settings ) ;
1887
1892
let bucket = lookUp ( buckets , key ) ;
1888
1893
if ( ! bucket && createIfMissing ) {
1889
- buckets [ key ] = bucket = { } ;
1894
+ buckets [ key ] = bucket = new FileMap < DocumentRegistryEntry > ( getCanonicalFileName ) ;
1890
1895
}
1891
1896
return bucket ;
1892
1897
}
@@ -1896,7 +1901,7 @@ module ts {
1896
1901
let entries = lookUp ( buckets , name ) ;
1897
1902
let sourceFiles : { name : string ; refCount : number ; references : string [ ] ; } [ ] = [ ] ;
1898
1903
for ( let i in entries ) {
1899
- let entry = entries [ i ] ;
1904
+ let entry = entries . get ( i ) ;
1900
1905
sourceFiles . push ( {
1901
1906
name : i ,
1902
1907
refCount : entry . languageServiceRefCount ,
@@ -1928,18 +1933,19 @@ module ts {
1928
1933
acquiring : boolean ) : SourceFile {
1929
1934
1930
1935
let bucket = getBucketForCompilationSettings ( compilationSettings , /*createIfMissing*/ true ) ;
1931
- let entry = lookUp ( bucket , fileName ) ;
1936
+ let entry = bucket . get ( fileName ) ;
1932
1937
if ( ! entry ) {
1933
1938
Debug . assert ( acquiring , "How could we be trying to update a document that the registry doesn't have?" ) ;
1934
1939
1935
1940
// Have never seen this file with these settings. Create a new source file for it.
1936
1941
let sourceFile = createLanguageServiceSourceFile ( fileName , scriptSnapshot , compilationSettings . target , version , /*setNodeParents:*/ false ) ;
1937
1942
1938
- bucket [ fileName ] = entry = {
1943
+ entry = {
1939
1944
sourceFile : sourceFile ,
1940
1945
languageServiceRefCount : 0 ,
1941
1946
owners : [ ]
1942
1947
} ;
1948
+ bucket . set ( fileName , entry ) ;
1943
1949
}
1944
1950
else {
1945
1951
// We have an entry for this file. However, it may be for a different version of
@@ -1967,12 +1973,12 @@ module ts {
1967
1973
let bucket = getBucketForCompilationSettings ( compilationSettings , false ) ;
1968
1974
Debug . assert ( bucket !== undefined ) ;
1969
1975
1970
- let entry = lookUp ( bucket , fileName ) ;
1976
+ let entry = bucket . get ( fileName ) ;
1971
1977
entry . languageServiceRefCount -- ;
1972
1978
1973
1979
Debug . assert ( entry . languageServiceRefCount >= 0 ) ;
1974
1980
if ( entry . languageServiceRefCount === 0 ) {
1975
- delete bucket [ fileName ] ;
1981
+ bucket . delete ( fileName ) ;
1976
1982
}
1977
1983
}
1978
1984
@@ -2400,9 +2406,7 @@ module ts {
2400
2406
}
2401
2407
}
2402
2408
2403
- function getCanonicalFileName ( fileName : string ) {
2404
- return useCaseSensitivefileNames ? fileName : fileName . toLowerCase ( ) ;
2405
- }
2409
+ let getCanonicalFileName = createGetCanonicalFileName ( useCaseSensitivefileNames ) ;
2406
2410
2407
2411
function getValidSourceFile ( fileName : string ) : SourceFile {
2408
2412
fileName = normalizeSlashes ( fileName ) ;
0 commit comments