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

Add an optional integer offset to OwnedMemory Pin #15946

Merged
merged 3 commits into from
Jan 20, 2018
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
18 changes: 0 additions & 18 deletions src/mscorlib/shared/System/Buffers/MemoryHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,6 @@ public unsafe struct MemoryHandle : IDisposable
/// </summary>
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>
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 @@ -43,7 +43,7 @@ public Memory<T> Memory
/// <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.
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 @@ -244,8 +244,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 @@ -222,8 +222,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