Considder updating the code in src/coverlet.core/Coverage.cs [Line 203 - L278] (GetCoverageResult) to something like the following.
Should reduce the number of dictionary lookups from a minimum of 9 (maximum 14) to a constant of 5.
public CoverageResult GetCoverageResult()
{
this.CalculateCoverage();
var modules = new Modules();
foreach (var result in this._results)
{
var documents = new Documents();
foreach (var doc in result.Documents.Values)
{
if (!documents.TryGetValue(doc.Path, out var classes))
{
classes = new();
documents.Add(doc.Path, classes);
}
// Construct Line Results
foreach (var line in doc.Lines.Values)
{
if (!classes.TryGetValue(line.Class, out var methods))
{
methods = new();
classes.Add(line.Class, methods);
}
if (!methods.TryGetValue(line.Method, out var method))
{
method = new();
methods.Add(line.Method, method);
}
method.Lines.Add(line.Number, line.Hits);
}
// Construct Branch Results
foreach (var branch in doc.Branches.Values)
{
var branchInfo = new BranchInfo()
{
Line = branch.Number,
Hits = branch.Hits,
Offset = branch.Offset,
EndOffset = branch.EndOffset,
Path = branch.Path,
Ordinal = branch.Ordinal
};
if (!classes.TryGetValue(branch.Class, out var methods))
{
methods = new();
classes.Add(branch.Class, methods);
}
if (!methods.TryGetValue(branch.Method, out var method))
{
method = new();
methods.Add(branch.Method, method);
}
method.Branches.Add(branchInfo);
}
}
modules.Add(Path.GetFileName(result.ModulePath), documents);
this._instrumentationHelper.RestoreOriginalModule(result.ModulePath, this.Identifier);
}
... The rest of the method goes here
Considder updating the code in src/coverlet.core/Coverage.cs [Line 203 - L278] (GetCoverageResult) to something like the following.
Should reduce the number of dictionary lookups from a minimum of 9 (maximum 14) to a constant of 5.
... The rest of the method goes here