Skip to content

Commit 6cbdb62

Browse files
authored
Speed up getDefaultLibFilePriority (microsoft#394)
1 parent b218961 commit 6cbdb62

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

internal/compiler/fileloader.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func processAllProgramFiles(
4646
compilerOptions: compilerOptions,
4747
resolver: resolver,
4848
tasksByFileName: make(map[string]*parseTask),
49-
defaultLibraryPath: host.DefaultLibraryPath(),
49+
defaultLibraryPath: tspath.GetNormalizedAbsolutePath(host.DefaultLibraryPath(), host.GetCurrentDirectory()),
5050
comparePathsOptions: tspath.ComparePathsOptions{
5151
UseCaseSensitiveFileNames: host.FS().UseCaseSensitiveFileNames(),
5252
CurrentDirectory: host.GetCurrentDirectory(),
@@ -152,8 +152,13 @@ func (p *fileLoader) sortLibs(libFiles []*ast.SourceFile) {
152152
}
153153

154154
func (p *fileLoader) getDefaultLibFilePriority(a *ast.SourceFile) int {
155-
if tspath.ContainsPath(p.defaultLibraryPath, a.FileName(), p.comparePathsOptions) {
156-
basename := tspath.GetBaseFileName(a.FileName())
155+
// defaultLibraryPath and a.FileName() are absolute and normalized; a prefix check should suffice.
156+
defaultLibraryPath := tspath.RemoveTrailingDirectorySeparator(p.defaultLibraryPath)
157+
aFileName := a.FileName()
158+
159+
if strings.HasPrefix(aFileName, defaultLibraryPath) && len(aFileName) > len(defaultLibraryPath) && aFileName[len(defaultLibraryPath)] == tspath.DirectorySeparator {
160+
// avoid tspath.GetBaseFileName; we know these paths are already absolute and normalized.
161+
basename := aFileName[strings.LastIndexByte(aFileName, tspath.DirectorySeparator)+1:]
157162
if basename == "lib.d.ts" || basename == "lib.es6.d.ts" {
158163
return 0
159164
}

0 commit comments

Comments
 (0)