diff --git a/src/Draco.Coverage/CoverageResult.cs b/src/Draco.Coverage/CoverageResult.cs index c80807e65..eeedca746 100644 --- a/src/Draco.Coverage/CoverageResult.cs +++ b/src/Draco.Coverage/CoverageResult.cs @@ -7,6 +7,13 @@ namespace Draco.Coverage; /// public readonly struct CoverageResult(ImmutableArray hits) { + /// + /// Creates a new coverage result from the given shared memory. + /// + /// The shared memory containing the hit counts. + /// The coverage result. + public static CoverageResult FromSharedMemory(SharedMemory hits) => new([.. hits.Span]); + /// /// An empty coverage result. /// diff --git a/src/Draco.Coverage/InstrumentedAssembly.cs b/src/Draco.Coverage/InstrumentedAssembly.cs index cc6aba35d..5b46bc759 100644 --- a/src/Draco.Coverage/InstrumentedAssembly.cs +++ b/src/Draco.Coverage/InstrumentedAssembly.cs @@ -69,14 +69,14 @@ public static InstrumentedAssembly Create(Stream sourceStream, InstrumentationWe /// /// The sequence points of the weaved assembly. /// - public ImmutableArray SequencePoints => - this.sequencePoints ??= (ImmutableArray)this.SequencePointsField.GetValue(null)!; - private ImmutableArray? sequencePoints; + public SequencePoint[] SequencePoints => + this.sequencePoints ??= NotNullOrNotWeaved((SequencePoint[]?)this.SequencePointsField.GetValue(null)); + private SequencePoint[]? sequencePoints; /// /// Retrieves a copy of the coverage result. /// - public CoverageResult CoverageResult => new([.. this.HitsInstance]); + public CoverageResult CoverageResult => CoverageResult.FromSharedMemory(this.HitsInstance); /// /// The coverage collector type weaved into the assembly. @@ -102,9 +102,9 @@ public static InstrumentedAssembly Create(Stream sourceStream, InstrumentationWe /// /// The hits instance of the coverage collector. /// - internal int[] HitsInstance => - this.hitsInstance ??= NotNullOrNotWeaved((int[]?)this.HitsField.GetValue(null)); - private int[]? hitsInstance; + internal SharedMemory HitsInstance => + this.hitsInstance ??= NotNullOrNotWeaved((SharedMemory?)this.HitsField.GetValue(null)); + private SharedMemory? hitsInstance; private InstrumentedAssembly(Assembly weavedAssembly) {