Skip to content

Commit b0646df

Browse files
committed
implement review suggestions
1 parent 7e30e76 commit b0646df

File tree

14 files changed

+67
-45
lines changed

14 files changed

+67
-45
lines changed

src/ImageSharp/Advanced/AdvancedImageExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private static Configuration GetConfiguration(IConfigurationProvider source)
6161
/// </remarks>
6262
public static IMemoryGroup<TPixel> GetPixelMemoryGroup<TPixel>(this ImageFrame<TPixel> source)
6363
where TPixel : struct, IPixel<TPixel>
64-
=> source?.PixelBuffer.MemoryGroup.View ?? throw new ArgumentNullException(nameof(source));
64+
=> source?.PixelBuffer.FastMemoryGroup.View ?? throw new ArgumentNullException(nameof(source));
6565

6666
/// <summary>
6767
/// Gets the representation of the pixels as a <see cref="IMemoryGroup{T}"/> containing the backing pixel data of the image

src/ImageSharp/Image.Decode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal static Image<TPixel> CreateUninitialized<TPixel>(
3636
{
3737
Buffer2D<TPixel> uninitializedMemoryBuffer =
3838
configuration.MemoryAllocator.Allocate2D<TPixel>(width, height);
39-
return new Image<TPixel>(configuration, uninitializedMemoryBuffer.MemoryGroup, width, height, metadata);
39+
return new Image<TPixel>(configuration, uninitializedMemoryBuffer.FastMemoryGroup, width, height, metadata);
4040
}
4141

4242
/// <summary>

src/ImageSharp/Image.LoadPixelData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public static Image<TPixel> LoadPixelData<TPixel>(Configuration config, ReadOnly
120120

121121
var image = new Image<TPixel>(config, width, height);
122122
data = data.Slice(0, count);
123-
data.CopyTo(image.Frames.RootFrame.PixelBuffer.MemoryGroup);
123+
data.CopyTo(image.Frames.RootFrame.PixelBuffer.FastMemoryGroup);
124124

125125
return image;
126126
}

src/ImageSharp/ImageFrame.LoadPixelData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ internal static ImageFrame<TPixel> LoadPixelData<TPixel>(Configuration configura
4545
var image = new ImageFrame<TPixel>(configuration, width, height);
4646

4747
data = data.Slice(0, count);
48-
data.CopyTo(image.PixelBuffer.MemoryGroup);
48+
data.CopyTo(image.PixelBuffer.FastMemoryGroup);
4949

5050
return image;
5151
}

src/ImageSharp/ImageFrameCollection{TPixel}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ private ImageFrame<TPixel> CopyNonCompatibleFrame(ImageFrame source)
351351
this.parent.GetConfiguration(),
352352
source.Size(),
353353
source.Metadata.DeepClone());
354-
source.CopyPixelsTo(result.PixelBuffer.MemoryGroup);
354+
source.CopyPixelsTo(result.PixelBuffer.FastMemoryGroup);
355355
return result;
356356
}
357357
}

src/ImageSharp/ImageFrame{TPixel}.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ internal ImageFrame(Configuration configuration, ImageFrame<TPixel> source)
131131
Guard.NotNull(source, nameof(source));
132132

133133
this.PixelBuffer = this.GetConfiguration().MemoryAllocator.Allocate2D<TPixel>(source.PixelBuffer.Width, source.PixelBuffer.Height);
134-
source.PixelBuffer.MemoryGroup.CopyTo(this.PixelBuffer.MemoryGroup);
134+
source.PixelBuffer.FastMemoryGroup.CopyTo(this.PixelBuffer.FastMemoryGroup);
135135
}
136136

137137
/// <summary>
@@ -186,7 +186,7 @@ internal void CopyTo(Buffer2D<TPixel> target)
186186
throw new ArgumentException("ImageFrame<TPixel>.CopyTo(): target must be of the same size!", nameof(target));
187187
}
188188

189-
this.PixelBuffer.MemoryGroup.CopyTo(target.MemoryGroup);
189+
this.PixelBuffer.FastMemoryGroup.CopyTo(target.FastMemoryGroup);
190190
}
191191

192192
/// <summary>
@@ -222,15 +222,15 @@ internal override void CopyPixelsTo<TDestinationPixel>(MemoryGroup<TDestinationP
222222
{
223223
if (typeof(TPixel) == typeof(TDestinationPixel))
224224
{
225-
this.PixelBuffer.MemoryGroup.TransformTo(destination, (s, d) =>
225+
this.PixelBuffer.FastMemoryGroup.TransformTo(destination, (s, d) =>
226226
{
227227
Span<TPixel> d1 = MemoryMarshal.Cast<TDestinationPixel, TPixel>(d);
228228
s.CopyTo(d1);
229229
});
230230
return;
231231
}
232232

233-
this.PixelBuffer.MemoryGroup.TransformTo(destination, (s, d) =>
233+
this.PixelBuffer.FastMemoryGroup.TransformTo(destination, (s, d) =>
234234
{
235235
PixelOperations<TPixel>.Instance.To(this.GetConfiguration(), s, d);
236236
});
@@ -291,7 +291,7 @@ internal ImageFrame<TPixel2> CloneAs<TPixel2>(Configuration configuration)
291291
/// <param name="value">The value to initialize the bitmap with.</param>
292292
internal void Clear(TPixel value)
293293
{
294-
MemoryGroup<TPixel> group = this.PixelBuffer.MemoryGroup;
294+
MemoryGroup<TPixel> group = this.PixelBuffer.FastMemoryGroup;
295295

296296
if (value.Equals(default))
297297
{

src/ImageSharp/Memory/Buffer2DExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static IMemoryGroup<T> GetMemoryGroup<T>(this Buffer2D<T> buffer)
2424
where T : struct
2525
{
2626
Guard.NotNull(buffer, nameof(buffer));
27-
return buffer.MemoryGroup.View;
27+
return buffer.FastMemoryGroup.View;
2828
}
2929

3030
/// <summary>
@@ -42,12 +42,12 @@ internal static Span<T> GetSingleSpan<T>(this Buffer2D<T> buffer)
4242
where T : struct
4343
{
4444
Guard.NotNull(buffer, nameof(buffer));
45-
if (buffer.MemoryGroup.Count > 1)
45+
if (buffer.FastMemoryGroup.Count > 1)
4646
{
4747
throw new InvalidOperationException("GetSingleSpan is only valid for a single-buffer group!");
4848
}
4949

50-
return buffer.MemoryGroup.Single().Span;
50+
return buffer.FastMemoryGroup.Single().Span;
5151
}
5252

5353
/// <summary>
@@ -65,12 +65,12 @@ internal static Memory<T> GetSingleMemory<T>(this Buffer2D<T> buffer)
6565
where T : struct
6666
{
6767
Guard.NotNull(buffer, nameof(buffer));
68-
if (buffer.MemoryGroup.Count > 1)
68+
if (buffer.FastMemoryGroup.Count > 1)
6969
{
7070
throw new InvalidOperationException("GetSingleMemory is only valid for a single-buffer group!");
7171
}
7272

73-
return buffer.MemoryGroup.Single();
73+
return buffer.FastMemoryGroup.Single();
7474
}
7575

7676
/// <summary>

src/ImageSharp/Memory/Buffer2D{T}.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

src/ImageSharp/Memory/BufferArea{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public Span<T> GetRowSpan(int y)
9494
int xx = this.Rectangle.X;
9595
int width = this.Rectangle.Width;
9696

97-
return this.DestinationBuffer.MemoryGroup.GetBoundedSlice(yy + xx, width).Span;
97+
return this.DestinationBuffer.FastMemoryGroup.GetBoundedSlice(yy + xx, width).Span;
9898
}
9999

100100
/// <summary>
@@ -140,7 +140,7 @@ public void Clear()
140140
// Optimization for when the size of the area is the same as the buffer size.
141141
if (this.IsFullBufferArea)
142142
{
143-
this.DestinationBuffer.MemoryGroup.Clear();
143+
this.DestinationBuffer.FastMemoryGroup.Clear();
144144
return;
145145
}
146146

src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Consumed.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Memory
1111
internal abstract partial class MemoryGroup<T>
1212
{
1313
// Analogous to the "consumed" variant of MemorySource
14-
private class Consumed : MemoryGroup<T>
14+
private sealed class Consumed : MemoryGroup<T>
1515
{
1616
private readonly Memory<T>[] source;
1717

0 commit comments

Comments
 (0)