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

Add optional integer offset to OwnedMemory Pin #15410

Merged
merged 1 commit into from
Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/mscorlib/shared/System/Buffers/MemoryHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/mscorlib/shared/System/Buffers/OwnedMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Memory<T> Memory
}
}

public abstract MemoryHandle Pin();
public abstract MemoryHandle Pin(int offset = 0);

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

Expand Down
3 changes: 1 addition & 2 deletions src/mscorlib/shared/System/Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ public unsafe MemoryHandle Retain(bool pin = false)
{
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)
{
Expand Down
3 changes: 1 addition & 2 deletions src/mscorlib/shared/System/ReadOnlyMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ public unsafe MemoryHandle Retain(bool pin = false)
{
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)
{
Expand Down