From 1f2894af801be0dcfb1cb42216db599574155cea Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sat, 29 Feb 2020 17:17:20 +0100 Subject: [PATCH] BufferArea optimizations --- src/ImageSharp/Memory/BufferArea{T}.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/ImageSharp/Memory/BufferArea{T}.cs b/src/ImageSharp/Memory/BufferArea{T}.cs index f5cbc6953..076f7f37c 100644 --- a/src/ImageSharp/Memory/BufferArea{T}.cs +++ b/src/ImageSharp/Memory/BufferArea{T}.cs @@ -79,8 +79,12 @@ namespace SixLabors.ImageSharp.Memory /// /// The reference to the [0,0] element [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ref T GetReferenceToOrigin() => - ref this.GetRowSpan(0)[0]; + public ref T GetReferenceToOrigin() + { + int y = this.Rectangle.Y; + int x = this.Rectangle.X; + return ref this.DestinationBuffer.GetRowSpan(y)[x]; + } /// /// Gets a span to row 'y' inside this area. @@ -90,11 +94,11 @@ namespace SixLabors.ImageSharp.Memory [MethodImpl(MethodImplOptions.AggressiveInlining)] public Span GetRowSpan(int y) { - int yy = this.GetRowIndex(y); + int yy = this.Rectangle.Y + y; int xx = this.Rectangle.X; int width = this.Rectangle.Width; - return this.DestinationBuffer.FastMemoryGroup.GetBoundedSlice(yy + xx, width).Span; + return this.DestinationBuffer.GetRowSpan(yy).Slice(xx, width); } /// @@ -129,12 +133,6 @@ namespace SixLabors.ImageSharp.Memory return new BufferArea(this.DestinationBuffer, rectangle); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal int GetRowIndex(int y) - { - return (y + this.Rectangle.Y) * this.DestinationBuffer.Width; - } - public void Clear() { // Optimization for when the size of the area is the same as the buffer size.