@@ -4456,7 +4456,7 @@ export class ProjectService {
4456
4456
toRetainConfiguredProjects : Set < ConfiguredProject > | undefined ,
4457
4457
openFilesWithRetainedConfiguredProject : Set < Path > | undefined ,
4458
4458
externalProjectsRetainingConfiguredProjects : Set < string > | undefined ,
4459
- ) {
4459
+ ) : Set < ConfiguredProject > {
4460
4460
const toRemoveConfiguredProjects = new Set ( this . configuredProjects . values ( ) ) ;
4461
4461
const markOriginalProjectsAsUsed = ( project : Project ) => {
4462
4462
if ( project . originalConfiguredProjects && ( isConfiguredProject ( project ) || ! project . isOrphan ( ) ) ) {
@@ -4469,6 +4469,8 @@ export class ProjectService {
4469
4469
}
4470
4470
} ;
4471
4471
toRetainConfiguredProjects ?. forEach ( retainConfiguredProject ) ;
4472
+ // Everything needs to be retained, fast path to skip all the work
4473
+ if ( ! toRemoveConfiguredProjects . size ) return toRemoveConfiguredProjects ;
4472
4474
4473
4475
// Do not remove configured projects that are used as original projects of other
4474
4476
this . inferredProjects . forEach ( markOriginalProjectsAsUsed ) ;
@@ -4479,7 +4481,10 @@ export class ProjectService {
4479
4481
projects . forEach ( retainConfiguredProject ) ;
4480
4482
}
4481
4483
} ) ;
4482
- this . openFiles . forEach ( ( _projectRootPath , path ) => {
4484
+ // Everything needs to be retained, fast path to skip all the work
4485
+ if ( ! toRemoveConfiguredProjects . size ) return toRemoveConfiguredProjects ;
4486
+
4487
+ forEachEntry ( this . openFiles , ( _projectRootPath , path ) => {
4483
4488
if ( openFilesWithRetainedConfiguredProject ?. has ( path ) ) return ;
4484
4489
const info = this . getScriptInfoForPath ( path ) ! ;
4485
4490
// Part of external project
@@ -4491,15 +4496,21 @@ export class ProjectService {
4491
4496
) ;
4492
4497
if ( result ?. defaultProject ) {
4493
4498
result ?. seenProjects . forEach ( retainConfiguredProject ) ;
4499
+ // Everything needs to be retained, fast path to skip all the work
4500
+ if ( ! toRemoveConfiguredProjects . size ) return toRemoveConfiguredProjects ;
4494
4501
}
4495
4502
} ) ;
4496
4503
4504
+ // Everything needs to be retained, fast path to skip all the work
4505
+ if ( ! toRemoveConfiguredProjects . size ) return toRemoveConfiguredProjects ;
4506
+
4497
4507
// Retain all the configured projects that have pending updates
4498
4508
// or the ones that is referencing retained project (or to be retained)
4499
- this . configuredProjects . forEach ( project => {
4509
+ forEachEntry ( this . configuredProjects , project => {
4500
4510
if ( toRemoveConfiguredProjects . has ( project ) ) {
4501
4511
if ( isPendingUpdate ( project ) || forEachReferencedProject ( project , isRetained ) ) {
4502
4512
retainConfiguredProject ( project ) ;
4513
+ if ( ! toRemoveConfiguredProjects . size ) return toRemoveConfiguredProjects ;
4503
4514
}
4504
4515
}
4505
4516
} ) ;
0 commit comments