Browse Source

Use vectorized Span methods in DenseMatrix

pull/604/head
Jason Nelson 8 years ago
parent
commit
571c1e5929
  1. 39
      src/ImageSharp/Primitives/DenseMatrix{T}.cs

39
src/ImageSharp/Primitives/DenseMatrix{T}.cs

@ -105,6 +105,9 @@ namespace SixLabors.ImageSharp.Primitives
} }
} }
public Span<T> Span => new Span<T>(Data);
/// <summary> /// <summary>
/// Performs an implicit conversion from a <see cref="T:T[,]" /> to a <see cref=" DenseMatrix{T}" />. /// Performs an implicit conversion from a <see cref="T:T[,]" /> to a <see cref=" DenseMatrix{T}" />.
/// </summary> /// </summary>
@ -146,19 +149,13 @@ namespace SixLabors.ImageSharp.Primitives
/// </summary> /// </summary>
/// <param name="value">The value to fill each item with</param> /// <param name="value">The value to fill each item with</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Fill(T value) public void Fill(T value) => this.Span.Fill(value);
{
for (int i = 0; i < this.Data.Length; i++)
{
this.Data[i] = value;
}
}
/// <summary> /// <summary>
/// Clears the matrix setting each value to the default value for the element type /// Clears the matrix setting each value to the default value for the element type
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Clear() => Array.Clear(this.Data, 0, this.Data.Length); public void Clear() => this.Span.Clear();
/// <summary> /// <summary>
/// Checks the coordinates to ensure they are within bounds. /// Checks the coordinates to ensure they are within bounds.
@ -183,28 +180,10 @@ namespace SixLabors.ImageSharp.Primitives
} }
/// <inheritdoc/> /// <inheritdoc/>
public bool Equals(DenseMatrix<T> other) public bool Equals(DenseMatrix<T> other) =>
{ this.Columns == other.Columns &&
if (this.Columns != other.Columns) this.Rows == other.Rows &&
{ this.Span.SequenceEqual(other.Span);
return false;
}
if (this.Rows != other.Rows)
{
return false;
}
for (int i = 0; i < this.Data.Length; i++)
{
if (!this.Data[i].Equals(other.Data[i]))
{
return false;
}
}
return true;
}
/// <inheritdoc/> /// <inheritdoc/>
public override bool Equals(object obj) => obj is DenseMatrix<T> other && this.Equals(other); public override bool Equals(object obj) => obj is DenseMatrix<T> other && this.Equals(other);

Loading…
Cancel
Save