From 22449d642ad91fe5da6fc785cc5f5adfd01a38e7 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 29 Jul 2020 16:28:50 +0100 Subject: [PATCH] Use MemoryMarshal.CreateSpan --- Directory.Build.props | 26 +++++++++++-------- .../Jpeg/Components/GenericBlock8x8.cs | 10 ++++++- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 14c9da79d..0f9c5bdde 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -30,17 +30,17 @@ @@ -52,6 +52,7 @@ $(DefineConstants);SUPPORTS_RUNTIME_INTRINSICS $(DefineConstants);SUPPORTS_CODECOVERAGE $(DefineConstants);SUPPORTS_HOTPATH + $(DefineConstants);SUPPORTS_CREATESPAN $(DefineConstants);SUPPORTS_MATHF @@ -60,10 +61,12 @@ $(DefineConstants);SUPPORTS_SPAN_STREAM $(DefineConstants);SUPPORTS_ENCODING_STRING $(DefineConstants);SUPPORTS_CODECOVERAGE + $(DefineConstants);SUPPORTS_CREATESPAN $(DefineConstants);SUPPORTS_MATHF $(DefineConstants);SUPPORTS_CODECOVERAGE + $(DefineConstants);SUPPORTS_CREATESPAN $(DefineConstants);SUPPORTS_MATHF @@ -71,6 +74,7 @@ $(DefineConstants);SUPPORTS_SPAN_STREAM $(DefineConstants);SUPPORTS_ENCODING_STRING $(DefineConstants);SUPPORTS_CODECOVERAGE + $(DefineConstants);SUPPORTS_CREATESPAN $(DefineConstants);SUPPORTS_CODECOVERAGE diff --git a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs index 38b902b88..92ba1afd3 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs @@ -109,6 +109,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components /// /// Only for on-stack instances! /// - public Span AsSpanUnsafe() => new Span(Unsafe.AsPointer(ref this), Size); + public Span AsSpanUnsafe() + { +#if SUPPORTS_CREATESPAN + Span> s = MemoryMarshal.CreateSpan(ref this, 1); + return MemoryMarshal.Cast, T>(s); +#else + return new Span(Unsafe.AsPointer(ref this), Size); +#endif + } } }