Remove MemoryManager.Length (#17498)
[platform/upstream/coreclr.git] / src / mscorlib / shared / System / Memory.cs
index c3affff..a500ec5 100644 (file)
@@ -115,27 +115,50 @@ namespace System
 
         /// <summary>
         /// Creates a new memory from a memory manager that provides specific method implementations beginning
+        /// at 0 index and ending at 'end' index (exclusive).
+        /// </summary>
+        /// <param name="manager">The memory manager.</param>
+        /// <param name="length">The number of items in the memory.</param>
+        /// <exception cref="System.ArgumentOutOfRangeException">
+        /// Thrown when the specified <paramref name="length"/> is negative.
+        /// </exception>
+        /// <remarks>For internal infrastructure only</remarks>
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        internal Memory(MemoryManager<T> manager, int length)
+        {
+            Debug.Assert(manager != null);
+
+            if (length < 0)
+                ThrowHelper.ThrowArgumentOutOfRangeException();
+
+            _object = manager;
+            _index = (1 << 31); // Mark as MemoryManager type
+            // Before using _index, check if _index < 0, then 'and' it with RemoveFlagsBitMask
+            _length = length;
+        }
+
+        /// <summary>
+        /// Creates a new memory from a memory manager that provides specific method implementations beginning
         /// at 'start' index and ending at 'end' index (exclusive).
         /// </summary>
         /// <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>
-        /// <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 (&lt;0 or &gt;=Length).
+        /// Thrown when the specified <paramref name="start"/> or <paramref name="length"/> is negative.
         /// </exception>
+        /// <remarks>For internal infrastructure only</remarks>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public Memory(MemoryManager<T> manager, int start, int length)
+        internal Memory(MemoryManager<T> manager, int start, int length)
         {
-            if (manager == null)
-                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.manager);
-            if ((uint)start > (uint)manager.Length || (uint)length > (uint)(manager.Length - start))
+            Debug.Assert(manager != null);
+
+            if (length < 0 || start < 0)
                 ThrowHelper.ThrowArgumentOutOfRangeException();
 
             _object = manager;
-            _index = start | (1 << 31); // Before using _index, check if _index < 0, then 'and' it with RemoveFlagsBitMask
+            _index = start | (1 << 31); // Mark as MemoryManager type
+            // Before using _index, check if _index < 0, then 'and' it with RemoveFlagsBitMask
             _length = length;
         }