Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 8931cfa

Browse files
ahsonkhanjkotas
authored andcommitted
Add optional integer offset to OwnedMemory Pin (#15410)
1 parent 0919eb3 commit 8931cfa

File tree

4 files changed

+3
-17
lines changed

4 files changed

+3
-17
lines changed

src/mscorlib/shared/System/Buffers/MemoryHandle.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@ public unsafe struct MemoryHandle : IDisposable
2121
_handle = handle;
2222
}
2323

24-
internal void AddOffset(int offset)
25-
{
26-
if (_pointer == null)
27-
{
28-
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.pointer);
29-
}
30-
else
31-
{
32-
_pointer = (void*)((byte*)_pointer + offset);
33-
}
34-
}
35-
3624
[CLSCompliant(false)]
3725
public void* Pointer => _pointer;
3826

src/mscorlib/shared/System/Buffers/OwnedMemory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public Memory<T> Memory
2525
}
2626
}
2727

28-
public abstract MemoryHandle Pin();
28+
public abstract MemoryHandle Pin(int offset = 0);
2929

3030
protected internal abstract bool TryGetArray(out ArraySegment<T> arraySegment);
3131

src/mscorlib/shared/System/Memory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ public unsafe MemoryHandle Retain(bool pin = false)
233233
{
234234
if (_index < 0)
235235
{
236-
memoryHandle = ((OwnedMemory<T>)_object).Pin();
237-
memoryHandle.AddOffset((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
236+
memoryHandle = ((OwnedMemory<T>)_object).Pin((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
238237
}
239238
else if (typeof(T) == typeof(char) && _object is string s)
240239
{

src/mscorlib/shared/System/ReadOnlyMemory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ public unsafe MemoryHandle Retain(bool pin = false)
215215
{
216216
if (_index < 0)
217217
{
218-
memoryHandle = ((OwnedMemory<T>)_object).Pin();
219-
memoryHandle.AddOffset((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
218+
memoryHandle = ((OwnedMemory<T>)_object).Pin((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
220219
}
221220
else if (typeof(T) == typeof(char) && _object is string s)
222221
{

0 commit comments

Comments
 (0)