Add optional integer offset to OwnedMemory Pin (#15946)
authorAhson Khan <ahkha@microsoft.com>
Sat, 20 Jan 2018 14:40:44 +0000 (06:40 -0800)
committerJan Kotas <jkotas@microsoft.com>
Sat, 20 Jan 2018 14:40:44 +0000 (06:40 -0800)
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 01f9563..7544038 100644 (file)
@@ -42,24 +42,6 @@ namespace System.Buffers
         public bool HasPointer => _pointer != null;
 
         /// <summary>
-        /// Adds an offset to the pinned pointer.
-        /// </summary>
-        /// <exception cref="System.ArgumentNullException">
-        /// Throw when pinned pointer is null.
-        /// </exception>
-        internal void AddOffset(int offset)
-        {
-            if (_pointer == null)
-            {
-                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.pointer);
-            }
-            else
-            {
-                _pointer = (void*)((byte*)_pointer + offset);
-            }
-        }
-
-        /// <summary>
         /// Frees the pinned handle and releases IRetainable.
         /// </summary>
        public void Dispose()
index bbde61b..b2d7a74 100644 (file)
@@ -43,7 +43,7 @@ namespace System.Buffers
         /// <summary>
         /// Returns a handle for the array that has been pinned and hence its address can be taken
         /// </summary>
-        public abstract MemoryHandle Pin();
+        public abstract MemoryHandle Pin(int offset = 0);
 
         /// <summary>
         /// Returns an array segment.
index 9cb6e38..7e89051 100644 (file)
@@ -244,8 +244,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 d0f8a47..c09f012 100644 (file)
@@ -222,8 +222,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)
                 {