07-23-2024
07:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
07-23-2024
07:27 AM
It's getting stranger and stranger...
With my test assembly (2650 files & 10000 Occurrences), the following code takes about 1.5 seconds. Always. The assembly is already open.
ComponentOccurrences occs = assmDoc.ComponentDefinition.Occurrences;
foreach (Document document in assmDoc.AllReferencedDocuments)
{
if (IsMatching(document, sd))
{
ComponentOccurrencesEnumerator leafOccs = occs.get_AllReferencedOccurrences(document);
foreach (ComponentOccurrence occ in leafOccs)
{
oCol.Add(occ);
}
}
}Traversing the assembly occurrences leads to the same result:
foreach (ComponentOccurrence occ in assmDoc.ComponentDefinition.Occurrences)
{
if (IsMatching(occ.Definition.Document as Document, sd))
oCol.Add(occ);
if (occ.SubOccurrences.Count > 0)
TraverseAssembly(occ.SubOccurrences, sd, oCol);
}
......
private static void TraverseAssembly(ComponentOccurrencesEnumerator subOccurrences, SearchDefinition sd, ObjectCollection oCol)
{
foreach(ComponentOccurrence occ in subOccurrences)
{
if (IsMatching(occ.Definition.Document as Document, sd))
oCol.Add(occ);
if (occ.SubOccurrences.Count > 0)
TraverseAssembly(occ.SubOccurrences, sd, oCol);
}
}But it takes 17 seconds for the first call, and a quick glance for subsequent calls ( < 500 mSec).