Remove IEnumerable<PointF> construction in CubicBezierLineSegment (eliminating allocation)

This commit is contained in:
Jason Nelson 2018-08-23 19:10:31 -07:00
Родитель 691f199c54
Коммит a9480629b0
1 изменённых файлов: 4 добавлений и 14 удалений

Просмотреть файл

@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using SixLabors.Primitives;
@ -29,10 +28,10 @@ namespace SixLabors.Shapes
/// Initializes a new instance of the <see cref="CubicBezierLineSegment"/> class.
/// </summary>
/// <param name="points">The points.</param>
public CubicBezierLineSegment(IEnumerable<PointF> points)
public CubicBezierLineSegment(PointF[] points)
{
Guard.NotNull(points, nameof(points));
this.controlPoints = points.ToArray();
this.controlPoints = points ?? throw new ArgumentNullException(nameof(points));
Guard.MustBeGreaterThanOrEqualTo(this.controlPoints.Length, 4, nameof(points));
int correctPointCount = (this.controlPoints.Length - 1) % 3;
@ -46,15 +45,6 @@ namespace SixLabors.Shapes
this.EndPoint = this.controlPoints[this.controlPoints.Length - 1];
}
/// <summary>
/// Initializes a new instance of the <see cref="CubicBezierLineSegment"/> class.
/// </summary>
/// <param name="points">The points.</param>
public CubicBezierLineSegment(PointF[] points)
: this((IEnumerable<PointF>)points)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="CubicBezierLineSegment"/> class.
/// </summary>
@ -64,7 +54,7 @@ namespace SixLabors.Shapes
/// <param name="end">The end.</param>
/// <param name="additionalPoints">The additional points.</param>
public CubicBezierLineSegment(PointF start, PointF controlPoint1, PointF controlPoint2, PointF end, params PointF[] additionalPoints)
: this(new[] { start, controlPoint1, controlPoint2, end }.Concat(additionalPoints))
: this(new[] { start, controlPoint1, controlPoint2, end }.Merge(additionalPoints))
{
}