Skip to content

Commit 0d13ad5

Browse files
Use MemoryMarshal.CreateSpan
1 parent 307668e commit 0d13ad5

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

Directory.Build.props

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@
3030

3131
<!--
3232
https://apisof.net/
33-
+===================+=======+==========+=====================+=============+=================+====================+==============+=========+
34-
| SUPPORTS | MATHF | HASHCODE | EXTENDED_INTRINSICS | SPAN_STREAM | ENCODING_STRING | RUNTIME_INTRINSICS | CODECOVERAGE | HOTPATH |
35-
+===================+=======+==========+=====================+=============+=================+====================+==============+=========|
36-
| netcoreapp3.1 | Y | Y | Y | Y | Y | Y | Y | Y |
37-
| netcoreapp2.1 | Y | Y | Y | Y | Y | N | Y | N |
38-
| netcoreapp2.0 | Y | N | N | N | N | N | Y | N |
39-
| netstandard2.1 | Y | Y | N | Y | Y | N | Y | N |
40-
| netstandard2.0 | N | N | N | N | N | N | Y | N |
41-
| netstandard1.3 | N | N | N | N | N | N | N | N |
42-
| net472 | N | N | Y | N | N | N | Y | N |
43-
+===================+=======+==========+=====================+=============+=================+====================+==============+=========|
33+
+===================+=======+==========+=====================+=============+=================+====================+==============+=========+============|
34+
| SUPPORTS | MATHF | HASHCODE | EXTENDED_INTRINSICS | SPAN_STREAM | ENCODING_STRING | RUNTIME_INTRINSICS | CODECOVERAGE | HOTPATH | CREATESPAN |
35+
+===================+=======+==========+=====================+=============+=================+====================+==============+=========|============|
36+
| netcoreapp3.1 | Y | Y | Y | Y | Y | Y | Y | Y | Y |
37+
| netcoreapp2.1 | Y | Y | Y | Y | Y | N | Y | N | Y |
38+
| netcoreapp2.0 | Y | N | N | N | N | N | Y | N | Y |
39+
| netstandard2.1 | Y | Y | N | Y | Y | N | Y | N | Y |
40+
| netstandard2.0 | N | N | N | N | N | N | Y | N | N |
41+
| netstandard1.3 | N | N | N | N | N | N | N | N | N |
42+
| net472 | N | N | Y | N | N | N | Y | N | N |
43+
+===================+=======+==========+=====================+=============+=================+====================+==============+=========|============|
4444
-->
4545

4646
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
@@ -52,6 +52,7 @@
5252
<DefineConstants>$(DefineConstants);SUPPORTS_RUNTIME_INTRINSICS</DefineConstants>
5353
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
5454
<DefineConstants>$(DefineConstants);SUPPORTS_HOTPATH</DefineConstants>
55+
<DefineConstants>$(DefineConstants);SUPPORTS_CREATESPAN</DefineConstants>
5556
</PropertyGroup>
5657
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
5758
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
@@ -60,17 +61,20 @@
6061
<DefineConstants>$(DefineConstants);SUPPORTS_SPAN_STREAM</DefineConstants>
6162
<DefineConstants>$(DefineConstants);SUPPORTS_ENCODING_STRING</DefineConstants>
6263
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
64+
<DefineConstants>$(DefineConstants);SUPPORTS_CREATESPAN</DefineConstants>
6365
</PropertyGroup>
6466
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
6567
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
6668
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
69+
<DefineConstants>$(DefineConstants);SUPPORTS_CREATESPAN</DefineConstants>
6770
</PropertyGroup>
6871
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
6972
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
7073
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
7174
<DefineConstants>$(DefineConstants);SUPPORTS_SPAN_STREAM</DefineConstants>
7275
<DefineConstants>$(DefineConstants);SUPPORTS_ENCODING_STRING</DefineConstants>
7376
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>
77+
<DefineConstants>$(DefineConstants);SUPPORTS_CREATESPAN</DefineConstants>
7478
</PropertyGroup>
7579
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
7680
<DefineConstants>$(DefineConstants);SUPPORTS_CODECOVERAGE</DefineConstants>

src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ public void LoadAndStretchEdges(Buffer2D<T> source, int sourceX, int sourceY, in
109109
/// <summary>
110110
/// Only for on-stack instances!
111111
/// </summary>
112-
public Span<T> AsSpanUnsafe() => new Span<T>(Unsafe.AsPointer(ref this), Size);
112+
public Span<T> AsSpanUnsafe()
113+
{
114+
#if SUPPORTS_CREATESPAN
115+
Span<GenericBlock8x8<T>> s = MemoryMarshal.CreateSpan(ref this, 1);
116+
return MemoryMarshal.Cast<GenericBlock8x8<T>, T>(s);
117+
#else
118+
return new Span<T>(Unsafe.AsPointer(ref this), Size);
119+
#endif
120+
}
113121
}
114122
}

0 commit comments

Comments
 (0)