From: Ian Hays Date: Mon, 22 Jan 2018 20:38:31 +0000 (-0800) Subject: Remove replaced Span/ReadOnlySpan methods. X-Git-Tag: accepted/tizen/unified/20190422.045933~3141^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=93ec62347a4e97b920513296eefb27bdacbecfe9;p=platform%2Fupstream%2Fcoreclr.git Remove replaced Span/ReadOnlySpan methods. --- diff --git a/src/mscorlib/shared/System/ReadOnlySpan.cs b/src/mscorlib/shared/System/ReadOnlySpan.cs index 063732b..e97364e 100644 --- a/src/mscorlib/shared/System/ReadOnlySpan.cs +++ b/src/mscorlib/shared/System/ReadOnlySpan.cs @@ -102,19 +102,6 @@ namespace System _length = length; } - /// - /// Create a new read-only span over a portion of a regular managed object. This can be useful - /// if part of a managed object represents a "fixed array." This is dangerous because neither the - /// is checked, nor being null, nor the fact that - /// "rawPointer" actually lies within . - /// - /// The managed object that contains the data to span over. - /// A reference to data within that object. - /// The number of elements the memory contains. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [EditorBrowsable(EditorBrowsableState.Never)] - public static ReadOnlySpan DangerousCreate(object obj, ref T objectData, int length) => new ReadOnlySpan(ref objectData, length); - // Constructor for internal use only. [MethodImpl(MethodImplOptions.AggressiveInlining)] internal ReadOnlySpan(ref T ptr, int length) diff --git a/src/mscorlib/shared/System/Runtime/InteropServices/MemoryMarshal.Fast.cs b/src/mscorlib/shared/System/Runtime/InteropServices/MemoryMarshal.Fast.cs index 4e0caed..6362209 100644 --- a/src/mscorlib/shared/System/Runtime/InteropServices/MemoryMarshal.Fast.cs +++ b/src/mscorlib/shared/System/Runtime/InteropServices/MemoryMarshal.Fast.cs @@ -50,7 +50,6 @@ namespace System.Runtime.InteropServices /// /// Thrown when or contains pointers. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Span Cast(Span source) where TFrom : struct where TTo : struct @@ -76,7 +75,6 @@ namespace System.Runtime.InteropServices /// /// Thrown when or contains pointers. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan Cast(ReadOnlySpan source) where TFrom : struct where TTo : struct diff --git a/src/mscorlib/shared/System/Span.NonGeneric.cs b/src/mscorlib/shared/System/Span.NonGeneric.cs index 7c942f8..9ce6acd 100644 --- a/src/mscorlib/shared/System/Span.NonGeneric.cs +++ b/src/mscorlib/shared/System/Span.NonGeneric.cs @@ -132,58 +132,6 @@ namespace System } /// - /// Casts a Span of one primitive type to another primitive type . - /// These types may not contain pointers or references. This is checked at runtime in order to preserve type safety. - /// - /// - /// Supported only for platforms that support misaligned memory access. - /// - /// The source slice, of type . - /// - /// Thrown when or contains pointers. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Span NonPortableCast(this Span source) - where TFrom : struct - where TTo : struct - { - if (RuntimeHelpers.IsReferenceOrContainsReferences()) - ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TFrom)); - if (RuntimeHelpers.IsReferenceOrContainsReferences()) - ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TTo)); - - return new Span( - ref Unsafe.As(ref source.DangerousGetPinnableReference()), - checked((int)((long)source.Length * Unsafe.SizeOf() / Unsafe.SizeOf()))); - } - - /// - /// Casts a ReadOnlySpan of one primitive type to another primitive type . - /// These types may not contain pointers or references. This is checked at runtime in order to preserve type safety. - /// - /// - /// Supported only for platforms that support misaligned memory access. - /// - /// The source slice, of type . - /// - /// Thrown when or contains pointers. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpan NonPortableCast(this ReadOnlySpan source) - where TFrom : struct - where TTo : struct - { - if (RuntimeHelpers.IsReferenceOrContainsReferences()) - ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TFrom)); - if (RuntimeHelpers.IsReferenceOrContainsReferences()) - ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TTo)); - - return new ReadOnlySpan( - ref Unsafe.As(ref MemoryMarshal.GetReference(source)), - checked((int)((long)source.Length * Unsafe.SizeOf() / Unsafe.SizeOf()))); - } - - /// /// Creates a new readonly span over the portion of the target string. /// /// The target string. diff --git a/src/mscorlib/shared/System/Span.cs b/src/mscorlib/shared/System/Span.cs index d96f4b1..22be6b7 100644 --- a/src/mscorlib/shared/System/Span.cs +++ b/src/mscorlib/shared/System/Span.cs @@ -108,19 +108,6 @@ namespace System _length = length; } - /// - /// Create a new span over a portion of a regular managed object. This can be useful - /// if part of a managed object represents a "fixed array." This is dangerous because neither the - /// is checked, nor being null, nor the fact that - /// "rawPointer" actually lies within . - /// - /// The managed object that contains the data to span over. - /// A reference to data within that object. - /// The number of elements the memory contains. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [EditorBrowsable(EditorBrowsableState.Never)] - public static Span DangerousCreate(object obj, ref T objectData, int length) => new Span(ref objectData, length); - // Constructor for internal use only. [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Span(ref T ptr, int length) diff --git a/tests/src/JIT/Performance/CodeQuality/Span/SpanBench.cs b/tests/src/JIT/Performance/CodeQuality/Span/SpanBench.cs index 5bf5a2f..fdb0a51 100644 --- a/tests/src/JIT/Performance/CodeQuality/Span/SpanBench.cs +++ b/tests/src/JIT/Performance/CodeQuality/Span/SpanBench.cs @@ -475,41 +475,41 @@ namespace Span } #endregion - #region TestSpanDangerousCreate + #region TestSpanCreate [Benchmark(InnerIterationCount = BaseIterations)] [InlineData(100)] - public static void TestSpanDangerousCreateByte(int length) + public static void TestSpanCreateByte(int length) { - InvokeTestSpanDangerousCreate(length); + InvokeTestSpanCreate(length); } [Benchmark(InnerIterationCount = BaseIterations)] [InlineData(100)] - public static void TestSpanDangerousCreateString(int length) + public static void TestSpanCreateString(int length) { - InvokeTestSpanDangerousCreate(length); + InvokeTestSpanCreate(length); } - static void InvokeTestSpanDangerousCreate(int length) + static void InvokeTestSpanCreate(int length) { TestClass testClass = new TestClass(); testClass.C0 = new T[length]; - Invoke((int innerIterationCount) => TestSpanDangerousCreate(testClass, innerIterationCount, false), - "TestSpanDangerousCreate<{0}>({1})", typeof(T).Name, length); + Invoke((int innerIterationCount) => TestSpanCreate(testClass, innerIterationCount, false), + "TestSpanCreate<{0}>({1})", typeof(T).Name, length); } [MethodImpl(MethodImplOptions.NoInlining)] - static void TestSpanDangerousCreate(TestClass testClass, int iterationCount, bool untrue) + static void TestSpanCreate(TestClass testClass, int iterationCount, bool untrue) { var sink = Sink.Instance; for (int i = 0; i < iterationCount; i++) { - var span = Span.DangerousCreate(testClass, ref testClass.C0[0], testClass.C0.Length); + var span = MemoryMarshal.CreateSpan(ref testClass.C0[0], testClass.C0.Length); // Under a condition that we know is false but the jit doesn't, // add a read from 'span' to make sure it's not dead, and an assignment - // to 'testClass' so the DangerousCreate call won't get hoisted. + // to 'testClass' so the Create call won't get hoisted. if (untrue) { sink.Data = span[0]; testClass = new TestClass(); } } } @@ -967,33 +967,33 @@ namespace Span } #endregion - #region TestSpanNonPortableCast + #region TestSpanCast [Benchmark(InnerIterationCount = BaseIterations)] [InlineData(100)] - public static void TestSpanNonPortableCastFromByteToInt(int length) + public static void TestSpanCastFromByteToInt(int length) { - InvokeTestSpanNonPortableCast(length); + InvokeTestSpanCast(length); } [Benchmark(InnerIterationCount = BaseIterations)] [InlineData(100)] - public static void TestSpanNonPortableCastFromIntToByte(int length) + public static void TestSpanCastFromIntToByte(int length) { - InvokeTestSpanNonPortableCast(length); + InvokeTestSpanCast(length); } - static void InvokeTestSpanNonPortableCast(int length) + static void InvokeTestSpanCast(int length) where From : struct where To : struct { var array = new From[length]; - Invoke((int innerIterationCount) => TestSpanNonPortableCast(array, innerIterationCount, false), - "TestSpanNonPortableCast<{0}, {1}>({2})", typeof(From).Name, typeof(To).Name, length); + Invoke((int innerIterationCount) => TestSpanCast(array, innerIterationCount, false), + "TestSpanCast<{0}, {1}>({2})", typeof(From).Name, typeof(To).Name, length); } [MethodImpl(MethodImplOptions.NoInlining)] - static void TestSpanNonPortableCast(From[] array, int iterationCount, bool untrue) + static void TestSpanCast(From[] array, int iterationCount, bool untrue) where From : struct where To : struct { @@ -1002,7 +1002,7 @@ namespace Span for (int i = 0; i < iterationCount; i++) { - var toSpan = span.NonPortableCast(); + var toSpan = MemoryMarshal.Cast(span); // Under a condition that we know is false but the jit doesn't, // add a read from 'toSpan' to make sure it's not dead, and an assignment // to 'span' so the AsBytes call won't get hoisted.