From 1dfe097dc0201564e61461731058569a20517183 Mon Sep 17 00:00:00 2001 From: Ahson Khan Date: Mon, 9 Apr 2018 22:00:13 -0700 Subject: Fix MemoryManager ctor, add unit and perf tests, and improve performance (#28880) * Fix MemoryManager ctor, add unit and perf tests, and improve performance. * Remove Dangerous Span Ctor * Fix sort order in csproj and rename Perf.MemorySlice.cs to Perf.Memory.Slice * Fix MemoryManager ctor and use internal span ctor to improve performance (#17452) * Fix MemoryManager ctor, add unit and perf tests, and use internal span ctor. * Address PR feedback (remove use of Unsafe.As and Dangerous Span Ctor) Signed-off-by: dotnet-bot-corefx-mirror --- src/System.Memory/tests/Memory/Span.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/System.Memory/tests/Memory/Span.cs') diff --git a/src/System.Memory/tests/Memory/Span.cs b/src/System.Memory/tests/Memory/Span.cs index 55ed001b3d..55956dd6ab 100644 --- a/src/System.Memory/tests/Memory/Span.cs +++ b/src/System.Memory/tests/Memory/Span.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Buffers; +using System.Runtime.InteropServices; using Xunit; namespace System.MemoryTests @@ -41,6 +42,22 @@ namespace System.MemoryTests manager.Memory.Span.Validate(91, -92, 93, 94, -95); } + [Fact] + public static void SpanFromCtorArrayChar() + { + char[] a = { '1', '2', '3', '4', '-' }; + Memory memory; + + memory = new Memory(a); + memory.Span.Validate('1', '2', '3', '4', '-'); + + memory = new Memory(a, 0, a.Length); + memory.Span.Validate('1', '2', '3', '4', '-'); + + MemoryManager manager = new CustomMemoryForTest(a); + manager.Memory.Span.Validate('1', '2', '3', '4', '-'); + } + [Fact] public static void SpanFromCtorArrayObject() { @@ -59,6 +76,19 @@ namespace System.MemoryTests manager.Memory.Span.ValidateReferenceType(o1, o2); } + [Fact] + public static void SpanFromStringAsMemory() + { + string a = "1234-"; + ReadOnlyMemory memory; + + memory = a.AsMemory(); + MemoryMarshal.AsMemory(memory).Span.Validate('1', '2', '3', '4', '-'); + + memory = a.AsMemory(0, a.Length); + MemoryMarshal.AsMemory(memory).Span.Validate('1', '2', '3', '4', '-'); + } + [Fact] public static void SpanFromCtorArrayZeroLength() { -- cgit v1.2.3