@@ -66,7 +66,7 @@ public DeclarationFinder(IReadOnlyList<Declaration> declarations, IEnumerable<IA
66
66
declarations . Where ( declaration => ! declaration . IsBuiltIn )
67
67
. GroupBy ( declaration => declaration . DeclarationType )
68
68
. ToDictionary ( grouping => grouping . Key , grouping => grouping . ToArray ( ) ) ) ;
69
- _builtinEvents = new ConcurrentBag < Declaration > ( FindBuiltInEventHandlers ( declarations ) ) ;
69
+ _builtinEvents = new Lazy < ConcurrentBag < Declaration > > ( ( ) => FindBuiltInEventHandlers ( declarations ) ) ;
70
70
71
71
_projects = _projects = declarations . Where ( d => d . DeclarationType == DeclarationType . Project ) . ToList ( ) ;
72
72
_classes = _declarations . AllValues ( ) . Where ( d => d . DeclarationType == DeclarationType . ClassModule ) . ToList ( ) ;
@@ -146,12 +146,12 @@ public IEnumerable<Declaration> FindDeclarationsWithNonBaseAsType()
146
146
}
147
147
}
148
148
149
- private readonly ConcurrentBag < Declaration > _builtinEvents ;
149
+ private readonly Lazy < ConcurrentBag < Declaration > > _builtinEvents ;
150
150
public IEnumerable < Declaration > FindBuiltinEventHandlers ( )
151
151
{
152
152
lock ( ThreadLock )
153
153
{
154
- return _builtinEvents . ToList ( ) ;
154
+ return _builtinEvents . Value ;
155
155
}
156
156
}
157
157
@@ -622,7 +622,7 @@ private IEnumerable<Declaration> FindAllInReferencedProjectByPriority(Declaratio
622
622
}
623
623
}
624
624
625
- public static IEnumerable < Declaration > FindBuiltInEventHandlers ( IEnumerable < Declaration > declarations )
625
+ public static ConcurrentBag < Declaration > FindBuiltInEventHandlers ( IEnumerable < Declaration > declarations )
626
626
{
627
627
var declarationList = declarations . ToList ( ) ;
628
628
@@ -640,24 +640,24 @@ public static IEnumerable<Declaration> FindBuiltInEventHandlers(IEnumerable<Decl
640
640
641
641
var handlers = declarationList . Where ( item =>
642
642
// class module built-in events
643
- ( item . DeclarationType == DeclarationType . Procedure &&
644
- item . ParentDeclaration . DeclarationType == DeclarationType . ClassModule && (
645
- item . IdentifierName . Equals ( "Class_Initialize" , StringComparison . InvariantCultureIgnoreCase ) ||
646
- item . IdentifierName . Equals ( "Class_Terminate" , StringComparison . InvariantCultureIgnoreCase ) ) ) ||
647
- // standard module built-in handlers (Excel specific):
648
- ( host != null &&
649
- host . ApplicationName . Equals ( "Excel" , StringComparison . InvariantCultureIgnoreCase ) &&
650
- item . DeclarationType == DeclarationType . Procedure &&
651
- item . ParentDeclaration . DeclarationType == DeclarationType . ProceduralModule && (
652
- item . IdentifierName . Equals ( "auto_open" , StringComparison . InvariantCultureIgnoreCase ) ||
653
- item . IdentifierName . Equals ( "auto_close" , StringComparison . InvariantCultureIgnoreCase ) ) ) ||
654
- // user handlers:
655
- ( ! item . IsBuiltIn &&
656
- item . DeclarationType == DeclarationType . Procedure &&
657
- handlerNames . Contains ( item . IdentifierName ) )
658
- ) . ToList ( ) ;
659
-
660
- return handlers ;
643
+ ( item . DeclarationType == DeclarationType . Procedure &&
644
+ item . ParentDeclaration . DeclarationType == DeclarationType . ClassModule && (
645
+ item . IdentifierName . Equals ( "Class_Initialize" , StringComparison . InvariantCultureIgnoreCase ) ||
646
+ item . IdentifierName . Equals ( "Class_Terminate" , StringComparison . InvariantCultureIgnoreCase ) ) ) ||
647
+ // standard module built-in handlers (Excel specific):
648
+ ( host != null &&
649
+ host . ApplicationName . Equals ( "Excel" , StringComparison . InvariantCultureIgnoreCase ) &&
650
+ item . DeclarationType == DeclarationType . Procedure &&
651
+ item . ParentDeclaration . DeclarationType == DeclarationType . ProceduralModule && (
652
+ item . IdentifierName . Equals ( "auto_open" , StringComparison . InvariantCultureIgnoreCase ) ||
653
+ item . IdentifierName . Equals ( "auto_close" , StringComparison . InvariantCultureIgnoreCase ) ) ) ||
654
+ // user handlers:
655
+ ( ! item . IsBuiltIn &&
656
+ item . DeclarationType == DeclarationType . Procedure &&
657
+ handlerNames . Contains ( item . IdentifierName ) )
658
+ ) ;
659
+
660
+ return new ConcurrentBag < Declaration > ( handlers ) ;
661
661
}
662
662
}
663
663
}
0 commit comments