Skip to content

Commit

Permalink
Removed Reserve with ReadOnlyMemory ref
Browse files Browse the repository at this point in the history
This is no longer required according to the discussion in dotnet#952
  • Loading branch information
mjp41 committed Jan 17, 2017
1 parent df9be35 commit 86d42da
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 34 deletions.
4 changes: 0 additions & 4 deletions src/System.Slices/System/Buffers/OwnedMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ public void Release()
protected virtual void OnZeroReferences()
{ }

protected internal virtual DisposableReservation Reserve(ref ReadOnlyMemory<T> memory)
{
return new DisposableReservation(this, Id);
}

#endregion

Expand Down
2 changes: 1 addition & 1 deletion src/System.Slices/System/Buffers/ReadOnlyMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ReadOnlyMemory<T> Slice(int index, int length)

public DisposableReservation Reserve()
{
return _owner.Reserve(ref this);
return _owner.Memory.Reserve();
}

public unsafe bool TryGetPointer(out void* pointer)
Expand Down
29 changes: 0 additions & 29 deletions tests/System.Slices.Tests/MemoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,6 @@ public unsafe void ReferenceCounting()
Assert.False(owned.HasOutstandingReferences);
}

[Fact]
public unsafe void CopyOnReserve()
{
var owned = new CustomMemory();
ReadOnlyMemory<byte> memory = owned.Memory;
var slice = memory.Slice(0, 1);

// this copies on reserve
using (slice.Reserve()) {
Assert.Equal(0, owned.OnZeroRefencesCount);
Assert.True(owned.HasZeroReferences);
}
Assert.Equal(0, owned.OnZeroRefencesCount);
Assert.True(owned.HasZeroReferences);
}

[Fact]
public void AutoDispose()
{
Expand All @@ -162,19 +146,6 @@ public CustomMemory() : base(new byte[256], 0, 256) { }

public int OnZeroRefencesCount => _onZeroRefencesCount;

protected override DisposableReservation Reserve(ref ReadOnlyMemory<byte> memory)
{
if (memory.Length < Length) {
var copy = memory.Span.ToArray();
OwnedArray<byte> newOwned = copy;
memory = newOwned.Memory;
return memory.Reserve();
}
else {
return base.Reserve(ref memory);
}
}

protected override void OnZeroReferences()
{
_onZeroRefencesCount++;
Expand Down

0 comments on commit 86d42da

Please sign in to comment.