diff options
author | Ahson Khan <ahkha@microsoft.com> | 2018-04-09 15:49:04 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-09 15:49:04 -0700 |
commit | 09ea3a952e4c9df4b572f9c76e8e58f052f6f18f (patch) | |
tree | 3cf12dd9c879f1e035e2e3297bbdf7f1b020b8c6 /src/mscorlib/shared | |
parent | a788a72d5ac56ceb8285d14c87f9ccddc229be34 (diff) | |
download | coreclr-09ea3a952e4c9df4b572f9c76e8e58f052f6f18f.tar.gz coreclr-09ea3a952e4c9df4b572f9c76e8e58f052f6f18f.tar.bz2 coreclr-09ea3a952e4c9df4b572f9c76e8e58f052f6f18f.zip |
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)
Diffstat (limited to 'src/mscorlib/shared')
-rw-r--r-- | src/mscorlib/shared/System/Memory.cs | 13 | ||||
-rw-r--r-- | src/mscorlib/shared/System/ReadOnlyMemory.cs | 2 |
2 files changed, 8 insertions, 7 deletions
diff --git a/src/mscorlib/shared/System/Memory.cs b/src/mscorlib/shared/System/Memory.cs index 6eb5af665d..3ccb76b2e5 100644 --- a/src/mscorlib/shared/System/Memory.cs +++ b/src/mscorlib/shared/System/Memory.cs @@ -120,7 +120,9 @@ namespace System /// <param name="manager">The memory manager.</param> /// <param name="start">The index at which to begin the memory.</param> /// <param name="length">The number of items in the memory.</param> - /// <remarks>Returns default when <paramref name="manager"/> is null.</remarks> + /// <exception cref="System.ArgumentNullException"> + /// Thrown when <paramref name="manager"/> is null. + /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when the specified <paramref name="start"/> or end index is not in the range (<0 or >=Length). /// </exception> @@ -128,12 +130,7 @@ namespace System public Memory(MemoryManager<T> manager, int start, int length) { if (manager == null) - { - if (start != 0 || length != 0) - ThrowHelper.ThrowArgumentOutOfRangeException(); - this = default; - return; // returns default - } + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.manager); if ((uint)start > (uint)manager.Length || (uint)length > (uint)(manager.Length - start)) ThrowHelper.ThrowArgumentOutOfRangeException(); @@ -276,6 +273,7 @@ namespace System if (_index < 0) { Debug.Assert(_length >= 0); + Debug.Assert(_object != null); return ((MemoryManager<T>)_object).GetSpan().Slice(_index & RemoveFlagsBitMask, _length); } else if (typeof(T) == typeof(char) && _object is string s) @@ -335,6 +333,7 @@ namespace System { if (_index < 0) { + Debug.Assert(_object != null); return ((MemoryManager<T>)_object).Pin((_index & RemoveFlagsBitMask)); } else if (typeof(T) == typeof(char) && _object is string s) diff --git a/src/mscorlib/shared/System/ReadOnlyMemory.cs b/src/mscorlib/shared/System/ReadOnlyMemory.cs index ca0e7d888e..3e7884528e 100644 --- a/src/mscorlib/shared/System/ReadOnlyMemory.cs +++ b/src/mscorlib/shared/System/ReadOnlyMemory.cs @@ -187,6 +187,7 @@ namespace System if (_index < 0) { Debug.Assert(_length >= 0); + Debug.Assert(_object != null); return ((MemoryManager<T>)_object).GetSpan().Slice(_index & RemoveFlagsBitMask, _length); } else if (typeof(T) == typeof(char) && _object is string s) @@ -241,6 +242,7 @@ namespace System { if (_index < 0) { + Debug.Assert(_object != null); return ((MemoryManager<T>)_object).Pin((_index & RemoveFlagsBitMask)); } else if (typeof(T) == typeof(char) && _object is string s) |