From 59ea5c58252df8448eb75d83490a51f0cbfcf598 Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Wed, 6 Dec 2017 19:49:51 -0800 Subject: [PATCH] Add optional integer offset to OwnedMemory Pin --- src/mscorlib/shared/System/Buffers/MemoryHandle.cs | 12 ------------ src/mscorlib/shared/System/Buffers/OwnedMemory.cs | 2 +- src/mscorlib/shared/System/Memory.cs | 3 +-- src/mscorlib/shared/System/ReadOnlyMemory.cs | 3 +-- 4 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/mscorlib/shared/System/Buffers/MemoryHandle.cs b/src/mscorlib/shared/System/Buffers/MemoryHandle.cs index 60592144a591..8a6b8461aca0 100644 --- a/src/mscorlib/shared/System/Buffers/MemoryHandle.cs +++ b/src/mscorlib/shared/System/Buffers/MemoryHandle.cs @@ -21,18 +21,6 @@ public unsafe struct MemoryHandle : IDisposable _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; diff --git a/src/mscorlib/shared/System/Buffers/OwnedMemory.cs b/src/mscorlib/shared/System/Buffers/OwnedMemory.cs index 116767073dd7..5ed7d95aa92c 100644 --- a/src/mscorlib/shared/System/Buffers/OwnedMemory.cs +++ b/src/mscorlib/shared/System/Buffers/OwnedMemory.cs @@ -25,7 +25,7 @@ public Memory Memory } } - public abstract MemoryHandle Pin(); + public abstract MemoryHandle Pin(int offset = 0); protected internal abstract bool TryGetArray(out ArraySegment arraySegment); diff --git a/src/mscorlib/shared/System/Memory.cs b/src/mscorlib/shared/System/Memory.cs index e66a61e21024..2e85da7e9ca7 100644 --- a/src/mscorlib/shared/System/Memory.cs +++ b/src/mscorlib/shared/System/Memory.cs @@ -233,8 +233,7 @@ public unsafe MemoryHandle Retain(bool pin = false) { if (_index < 0) { - memoryHandle = ((OwnedMemory)_object).Pin(); - memoryHandle.AddOffset((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf()); + memoryHandle = ((OwnedMemory)_object).Pin((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf()); } 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 d68f622cce7a..18ad7a9673cb 100644 --- a/src/mscorlib/shared/System/ReadOnlyMemory.cs +++ b/src/mscorlib/shared/System/ReadOnlyMemory.cs @@ -215,8 +215,7 @@ public unsafe MemoryHandle Retain(bool pin = false) { if (_index < 0) { - memoryHandle = ((OwnedMemory)_object).Pin(); - memoryHandle.AddOffset((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf()); + memoryHandle = ((OwnedMemory)_object).Pin((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf()); } else if (typeof(T) == typeof(char) && _object is string s) {