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

Commit 7b55151

Browse files
authored
Merge pull request #15516 from jkotas/revert
Revert "Add optional integer offset to OwnedMemory Pin (#15410)"
2 parents b3dc9a7 + d91c7bb commit 7b55151

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ 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+
2436
[CLSCompliant(false)]
2537
public void* Pointer => _pointer;
2638

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(int offset = 0);
28+
public abstract MemoryHandle Pin();
2929

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

src/mscorlib/shared/System/Memory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ public unsafe MemoryHandle Retain(bool pin = false)
234234
{
235235
if (_index < 0)
236236
{
237-
memoryHandle = ((OwnedMemory<T>)_object).Pin((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
237+
memoryHandle = ((OwnedMemory<T>)_object).Pin();
238+
memoryHandle.AddOffset((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
238239
}
239240
else if (typeof(T) == typeof(char) && _object is string s)
240241
{

src/mscorlib/shared/System/ReadOnlyMemory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ public unsafe MemoryHandle Retain(bool pin = false)
216216
{
217217
if (_index < 0)
218218
{
219-
memoryHandle = ((OwnedMemory<T>)_object).Pin((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
219+
memoryHandle = ((OwnedMemory<T>)_object).Pin();
220+
memoryHandle.AddOffset((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
220221
}
221222
else if (typeof(T) == typeof(char) && _object is string s)
222223
{

0 commit comments

Comments
 (0)