Add optional integer offset to OwnedMemory Pin (#15410)
authorAhson Khan <ahkha@microsoft.com>
Fri, 8 Dec 2017 11:07:16 +0000 (03:07 -0800)
committerJan Kotas <jkotas@microsoft.com>
Fri, 8 Dec 2017 11:07:16 +0000 (06:07 -0500)
src/mscorlib/shared/System/Buffers/MemoryHandle.cs
src/mscorlib/shared/System/Buffers/OwnedMemory.cs
src/mscorlib/shared/System/Memory.cs
src/mscorlib/shared/System/ReadOnlyMemory.cs

index 60592144a5913653f75c5db6c36b7309b16ef925..8a6b8461aca098c0f05da497825b2024906088aa 100644 (file)
@@ -21,18 +21,6 @@ namespace System.Buffers
             _handle = handle;
         }
 
-        internal void AddOffset(int offset)
-        {
-            if (_pointer == null)
-            {
-                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.pointer);
-            }
-            else
-            {
-                _pointer = (void*)((byte*)_pointer + offset);
-            }
-        }
-
         [CLSCompliant(false)]
         public void* Pointer => _pointer;
 
index 116767073dd77363f3b9d6722a5718c48b01c915..5ed7d95aa92cb41b5973d698c117c3d5d0438e45 100644 (file)
@@ -25,7 +25,7 @@ namespace System.Buffers
             }
         }
 
-        public abstract MemoryHandle Pin();
+        public abstract MemoryHandle Pin(int offset = 0);
 
         protected internal abstract bool TryGetArray(out ArraySegment<T> arraySegment);
 
index e66a61e210244e00981f949ea8ce9430b49e9c97..2e85da7e9ca7d95e4d63d6610c2c9aceabeea044 100644 (file)
@@ -233,8 +233,7 @@ namespace System
             {
                 if (_index < 0)
                 {
-                    memoryHandle = ((OwnedMemory<T>)_object).Pin();
-                    memoryHandle.AddOffset((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
+                    memoryHandle = ((OwnedMemory<T>)_object).Pin((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
                 }
                 else if (typeof(T) == typeof(char) && _object is string s)
                 {
index bdf92ff65dd151eec4e427a3004365bacbd7a919..97b1ab7baaeebd259f0fda539eb4b9e18ba10f23 100644 (file)
@@ -215,8 +215,7 @@ namespace System
             {
                 if (_index < 0)
                 {
-                    memoryHandle = ((OwnedMemory<T>)_object).Pin();
-                    memoryHandle.AddOffset((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
+                    memoryHandle = ((OwnedMemory<T>)_object).Pin((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
                 }
                 else if (typeof(T) == typeof(char) && _object is string s)
                 {