Skip to content

Commit ff94d20

Browse files
Merge pull request #1465 from SixLabors/js/convolution-experiments
Optimize Convolution
2 parents 1f351ee + 863bddb commit ff94d20

File tree

15 files changed

+804
-504
lines changed

15 files changed

+804
-504
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@
105105
*.pvr binary
106106
*.snk binary
107107
*.tga binary
108+
*.tif binary
109+
*.tiff binary
108110
*.ttc binary
109111
*.ttf binary
112+
*.wbmp binary
110113
*.webp binary
111114
*.woff binary
112115
*.woff2 binary

src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs

Lines changed: 0 additions & 279 deletions
This file was deleted.

src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.Buffer{T}.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ public override Span<T> GetSpan()
5353
{
5454
ThrowObjectDisposedException();
5555
}
56-
56+
#if SUPPORTS_CREATESPAN
57+
ref byte r0 = ref MemoryMarshal.GetReference<byte>(this.Data);
58+
return MemoryMarshal.CreateSpan(ref Unsafe.As<byte, T>(ref r0), this.length);
59+
#else
5760
return MemoryMarshal.Cast<byte, T>(this.Data.AsSpan()).Slice(0, this.length);
61+
#endif
62+
5863
}
5964

6065
/// <inheritdoc />

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public DenseMatrix(T[,] data)
109109
/// <returns>The <see typeparam="T"/> at the specified position.</returns>
110110
public ref T this[int row, int column]
111111
{
112-
[MethodImpl(InliningOptions.ShortMethod)]
112+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
113113
get
114114
{
115115
this.CheckCoordinates(row, column);
@@ -124,7 +124,7 @@ public DenseMatrix(T[,] data)
124124
/// <returns>
125125
/// The <see cref="DenseMatrix{T}"/> representation on the source data.
126126
/// </returns>
127-
[MethodImpl(InliningOptions.ShortMethod)]
127+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
128128
public static implicit operator DenseMatrix<T>(T[,] data) => new DenseMatrix<T>(data);
129129

130130
/// <summary>
@@ -134,7 +134,7 @@ public DenseMatrix(T[,] data)
134134
/// <returns>
135135
/// The <see cref="T:T[,]"/> representation on the source data.
136136
/// </returns>
137-
[MethodImpl(InliningOptions.ShortMethod)]
137+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
138138
#pragma warning disable SA1008 // Opening parenthesis should be spaced correctly
139139
public static implicit operator T[,](in DenseMatrix<T> data)
140140
#pragma warning restore SA1008 // Opening parenthesis should be spaced correctly
@@ -175,7 +175,7 @@ public DenseMatrix(T[,] data)
175175
/// Transposes the rows and columns of the dense matrix.
176176
/// </summary>
177177
/// <returns>The <see cref="DenseMatrix{T}"/>.</returns>
178-
[MethodImpl(InliningOptions.ShortMethod)]
178+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
179179
public DenseMatrix<T> Transpose()
180180
{
181181
var result = new DenseMatrix<T>(this.Rows, this.Columns);
@@ -196,13 +196,13 @@ public DenseMatrix<T> Transpose()
196196
/// Fills the matrix with the given value
197197
/// </summary>
198198
/// <param name="value">The value to fill each item with</param>
199-
[MethodImpl(InliningOptions.ShortMethod)]
199+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
200200
public void Fill(T value) => this.Span.Fill(value);
201201

202202
/// <summary>
203203
/// Clears the matrix setting each value to the default value for the element type
204204
/// </summary>
205-
[MethodImpl(InliningOptions.ShortMethod)]
205+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
206206
public void Clear() => this.Span.Clear();
207207

208208
/// <summary>
@@ -232,14 +232,14 @@ public override bool Equals(object obj)
232232
=> obj is DenseMatrix<T> other && this.Equals(other);
233233

234234
/// <inheritdoc/>
235-
[MethodImpl(InliningOptions.ShortMethod)]
235+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
236236
public bool Equals(DenseMatrix<T> other) =>
237237
this.Columns == other.Columns
238238
&& this.Rows == other.Rows
239239
&& this.Span.SequenceEqual(other.Span);
240240

241241
/// <inheritdoc/>
242-
[MethodImpl(InliningOptions.ShortMethod)]
242+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
243243
public override int GetHashCode()
244244
{
245245
HashCode code = default;

0 commit comments

Comments
 (0)