Skip to content

Commit

Permalink
Add optional integer offset to OwnedMemory Pin (dotnet#15410)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsonkhan authored and jkotas committed Dec 8, 2017
1 parent 0919eb3 commit 8931cfa
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 17 deletions.
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

0 comments on commit 8931cfa

Please sign in to comment.