Skip to content

Commit 0285e5d

Browse files
committed
Reduce allocs in InternalPath
1 parent 4569fe7 commit 0285e5d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/ImageSharp.Drawing/Shapes/InternalPath.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Buffers;
55
using System.Numerics;
66
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
78
using SixLabors.ImageSharp.Memory;
89

910
namespace SixLabors.ImageSharp.Drawing;
@@ -61,7 +62,7 @@ internal InternalPath(ILineSegment segment, bool isClosedPath)
6162
/// <param name="points">The points.</param>
6263
/// <param name="isClosedPath">if set to <c>true</c> [is closed path].</param>
6364
internal InternalPath(ReadOnlyMemory<PointF> points, bool isClosedPath)
64-
: this(Simplify(points, isClosedPath, true), isClosedPath)
65+
: this(Simplify(points.Span, isClosedPath, true), isClosedPath)
6566
{
6667
}
6768

@@ -247,16 +248,14 @@ private static PointData[] Simplify(IReadOnlyList<ILineSegment> segments, bool i
247248
foreach (ILineSegment seg in segments)
248249
{
249250
ReadOnlyMemory<PointF> points = seg.Flatten();
250-
simplified.AddRange(points.ToArray());
251+
simplified.AddRange(points.Span);
251252
}
252253

253-
return Simplify(simplified.ToArray(), isClosed, removeCloseAndCollinear);
254+
return Simplify(CollectionsMarshal.AsSpan(simplified), isClosed, removeCloseAndCollinear);
254255
}
255256

256-
private static PointData[] Simplify(ReadOnlyMemory<PointF> vectors, bool isClosed, bool removeCloseAndCollinear)
257+
private static PointData[] Simplify(ReadOnlySpan<PointF> points, bool isClosed, bool removeCloseAndCollinear)
257258
{
258-
ReadOnlySpan<PointF> points = vectors.Span;
259-
260259
int polyCorners = points.Length;
261260
if (polyCorners == 0)
262261
{

0 commit comments

Comments
 (0)