Skip to content

Commit b66f7c5

Browse files
committed
Add Memory property to ISpanOwner
1 parent 8256663 commit b66f7c5

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CommunityToolkit.HighPerformance/Streams/Sources/ArrayOwner.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,14 @@ public Span<byte> Span
7474
#endif
7575
}
7676
}
77+
78+
/// <inheritdoc/>
79+
public Memory<byte> Memory
80+
{
81+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
82+
get
83+
{
84+
return this.array.AsMemory(this.offset, this.length);
85+
}
86+
}
7787
}

CommunityToolkit.HighPerformance/Streams/Sources/Interfaces/ISpanOwner.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ internal interface ISpanOwner
2020
/// Gets a <see cref="Span{T}"/> instance wrapping the underlying memory area.
2121
/// </summary>
2222
Span<byte> Span { get; }
23+
24+
/// <summary>
25+
/// Gets a <see cref="Memory{T}"/> instance wrapping the underlying memory area.
26+
/// </summary>
27+
Memory<byte> Memory { get; }
2328
}

CommunityToolkit.HighPerformance/Streams/Sources/MemoryManagerOwner.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,14 @@ public Span<byte> Span
6161
return this.memoryManager.GetSpan().Slice(this.offset, this.length);
6262
}
6363
}
64+
65+
/// <inheritdoc/>
66+
public Memory<byte> Memory
67+
{
68+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
69+
get
70+
{
71+
return this.memoryManager.Memory.Slice(this.offset, this.length);
72+
}
73+
}
6474
}

0 commit comments

Comments
 (0)