@@ -28,7 +28,7 @@ public sealed class Buffer2D<T> : IDisposable
2828 /// <param name="height">The number of rows.</param>
2929 internal Buffer2D ( MemoryGroup < T > memoryGroup , int width , int height )
3030 {
31- this . MemoryGroup = memoryGroup ;
31+ this . FastMemoryGroup = memoryGroup ;
3232 this . Width = width ;
3333 this . Height = height ;
3434
@@ -49,24 +49,31 @@ internal Buffer2D(MemoryGroup<T> memoryGroup, int width, int height)
4949 public int Height { get ; private set ; }
5050
5151 /// <summary>
52- /// Gets the backing <see cref="MemoryGroup{T}"/>.
52+ /// Gets the backing <see cref="IMemoryGroup{T}"/>.
53+ /// </summary>
54+ /// <returns>The MemoryGroup.</returns>
55+ public IMemoryGroup < T > MemoryGroup => this . FastMemoryGroup . View ;
56+
57+ /// <summary>
58+ /// Gets the backing <see cref="MemoryGroup{T}"/> without the view abstraction.
5359 /// </summary>
5460 /// <remarks>
5561 /// This property has been kept internal intentionally.
56- /// It's public counterpart is <see cref="Buffer2DExtensions.GetMemoryGroup{T} "/>,
62+ /// It's public counterpart is <see cref="MemoryGroup "/>,
5763 /// which only exposes the view of the MemoryGroup.
5864 /// </remarks>
59- internal MemoryGroup < T > MemoryGroup { get ; }
65+ internal MemoryGroup < T > FastMemoryGroup { get ; }
6066
6167 /// <summary>
6268 /// Gets a reference to the element at the specified position.
6369 /// </summary>
6470 /// <param name="x">The x coordinate (row)</param>
6571 /// <param name="y">The y coordinate (position at row)</param>
6672 /// <returns>A reference to the element.</returns>
67- internal ref T this [ int x , int y ]
73+ /// <exception cref="IndexOutOfRangeException">When index is out of range of the buffer.</exception>
74+ public ref T this [ int x , int y ]
6875 {
69- [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
76+ [ MethodImpl ( InliningOptions . ShortMethod ) ]
7077 get
7178 {
7279 DebugGuard . MustBeGreaterThanOrEqualTo ( x , 0 , nameof ( x ) ) ;
@@ -83,7 +90,7 @@ internal Buffer2D(MemoryGroup<T> memoryGroup, int width, int height)
8390 /// </summary>
8491 public void Dispose ( )
8592 {
86- this . MemoryGroup . Dispose ( ) ;
93+ this . FastMemoryGroup . Dispose ( ) ;
8794 this . cachedMemory = default ;
8895 }
8996
@@ -148,7 +155,7 @@ internal Memory<T> GetSafeRowMemory(int y)
148155 {
149156 DebugGuard . MustBeGreaterThanOrEqualTo ( y , 0 , nameof ( y ) ) ;
150157 DebugGuard . MustBeLessThan ( y , this . Height , nameof ( y ) ) ;
151- return this . MemoryGroup . View . GetBoundedSlice ( y * this . Width , this . Width ) ;
158+ return this . FastMemoryGroup . View . GetBoundedSlice ( y * this . Width , this . Width ) ;
152159 }
153160
154161 /// <summary>
@@ -157,12 +164,12 @@ internal Memory<T> GetSafeRowMemory(int y)
157164 /// </summary>
158165 internal static void SwapOrCopyContent ( Buffer2D < T > destination , Buffer2D < T > source )
159166 {
160- bool swap = MemoryGroup < T > . SwapOrCopyContent ( destination . MemoryGroup , source . MemoryGroup ) ;
167+ bool swap = MemoryGroup < T > . SwapOrCopyContent ( destination . FastMemoryGroup , source . FastMemoryGroup ) ;
161168 SwapOwnData ( destination , source , swap ) ;
162169 }
163170
164171 [ MethodImpl ( InliningOptions . ColdPath ) ]
165- private Memory < T > GetRowMemorySlow ( int y ) => this . MemoryGroup . GetBoundedSlice ( y * this . Width , this . Width ) ;
172+ private Memory < T > GetRowMemorySlow ( int y ) => this . FastMemoryGroup . GetBoundedSlice ( y * this . Width , this . Width ) ;
166173
167174 [ MethodImpl ( InliningOptions . ColdPath ) ]
168175 private ref T GetElementSlow ( int x , int y )
0 commit comments