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 6059214..8a6b846 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 1167670..5ed7d95 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 e66a61e..2e85da7 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 bdf92ff..97b1ab7 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)
                 {