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

Commit

Permalink
renamed buffer related types
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofCwalina committed Mar 20, 2017
1 parent 91a112c commit 536c65f
Show file tree
Hide file tree
Showing 53 changed files with 280 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Microsoft.Net.Http
{
class OwnedBuffer : OwnedMemory<byte>, IMemoryList<byte>, IReadOnlyMemoryList<byte>
class OwnedBuffer : OwnedBuffer<byte>, IMemoryList<byte>, IReadOnlyMemoryList<byte>
{
public const int DefaultBufferSize = 1024;
internal OwnedBuffer _next;
Expand All @@ -25,19 +25,19 @@ static void Free(byte[] array)
{
}

public Memory<byte> First => Memory;
public Buffer<byte> First => Memory;

public IMemoryList<byte> Rest => _next;

public int WrittenByteCount => _written;

ReadOnlyMemory<byte> IReadOnlyMemoryList<byte>.First => Memory;
ReadOnlyBuffer<byte> IReadOnlyMemoryList<byte>.First => Memory;

IReadOnlyMemoryList<byte> IReadOnlyMemoryList<byte>.Rest => _next;

// TODO: maybe these should be renamed to no conflict with OwnedMemory<T>.Length?
int? ISequence<Memory<byte>>.Length => null;
int? ISequence<ReadOnlyMemory<byte>>.Length => null;
int? ISequence<Buffer<byte>>.Length => null;
int? ISequence<ReadOnlyBuffer<byte>>.Length => null;

public int CopyTo(Span<byte> buffer)
{
Expand All @@ -50,14 +50,14 @@ public int CopyTo(Span<byte> buffer)
return buffer.Length;
}

public bool TryGet(ref Position position, out Memory<byte> item, bool advance = true)
public bool TryGet(ref Position position, out Buffer<byte> item, bool advance = true)
{
if (position == Position.First) {
item = Memory.Slice(0, _written);
if (advance) { position.IntegerPosition++; position.ObjectPosition = _next; }
return true;
}
else if (position.ObjectPosition == null) { item = default(Memory<byte>); return false; }
else if (position.ObjectPosition == null) { item = default(Buffer<byte>); return false; }

var sequence = (OwnedBuffer)position.ObjectPosition;
item = sequence.Memory.Slice(0, _written);
Expand All @@ -73,14 +73,14 @@ public bool TryGet(ref Position position, out Memory<byte> item, bool advance =
return true;
}

public bool TryGet(ref Position position, out ReadOnlyMemory<byte> item, bool advance = true)
public bool TryGet(ref Position position, out ReadOnlyBuffer<byte> item, bool advance = true)
{
if (position == Position.First) {
item = Memory.Slice(0, _written);
if (advance) { position.IntegerPosition++; position.ObjectPosition = _next; }
return true;
}
else if (position.ObjectPosition == null) { item = default(ReadOnlyMemory<byte>); return false; }
else if (position.ObjectPosition == null) { item = default(ReadOnlyBuffer<byte>); return false; }

var sequence = (OwnedBuffer)position.ObjectPosition;
item = sequence.Memory.Slice(0, _written);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

namespace System.Buffers
{
public interface IMemoryList<T> : ISequence<Memory<T>>
public interface IMemoryList<T> : ISequence<Buffer<T>>
{
int CopyTo(Span<T> buffer);
Memory<T> First { get; }
Buffer<T> First { get; }
IMemoryList<T> Rest { get; }
}

Expand All @@ -19,24 +19,24 @@ public interface IMemoryList<T> : ISequence<Memory<T>>
/// </summary>
public struct ReadWriteBytes : IMemoryList<byte>
{
Memory<byte> _first;
Buffer<byte> _first;
IMemoryList<byte> _rest;
int _length;

static readonly ReadWriteBytes s_empty = new ReadWriteBytes(Memory<byte>.Empty);
static readonly ReadWriteBytes s_empty = new ReadWriteBytes(Buffer<byte>.Empty);

public ReadWriteBytes(Memory<byte> first, IMemoryList<byte> rest, int length)
public ReadWriteBytes(Buffer<byte> first, IMemoryList<byte> rest, int length)
{
_rest = rest;
_first = first;
_length = length;
}

public ReadWriteBytes(Memory<byte> first, IMemoryList<byte> rest) :
public ReadWriteBytes(Buffer<byte> first, IMemoryList<byte> rest) :
this(first, rest, Unspecified)
{ }

public ReadWriteBytes(Memory<byte> memory) :
public ReadWriteBytes(Buffer<byte> memory) :
this(memory, null, memory.Length)
{ }

Expand All @@ -48,7 +48,7 @@ public ReadWriteBytes(IMemoryList<byte> segments) :
this(segments.First, segments.Rest, Unspecified)
{ }

public bool TryGet(ref Position position, out Memory<byte> value, bool advance = true)
public bool TryGet(ref Position position, out Buffer<byte> value, bool advance = true)
{
if (position == Position.First)
{
Expand All @@ -65,7 +65,7 @@ public bool TryGet(ref Position position, out Memory<byte> value, bool advance =
var rest = position.ObjectPosition as IMemoryList<byte>;
if (rest == null)
{
value = default(Memory<byte>);
value = default(Buffer<byte>);
return false;
}

Expand All @@ -85,7 +85,7 @@ public bool TryGet(ref Position position, out Memory<byte> value, bool advance =
return true;
}

public Memory<Byte> First => _first;
public Buffer<byte> First => _first;

public IMemoryList<byte> Rest => _rest;

Expand Down Expand Up @@ -147,7 +147,7 @@ ReadWriteBytes SliceRest(int index, int length)
{
if (First.Length == index && length == 0)
{
return new ReadWriteBytes(Memory<byte>.Empty);
return new ReadWriteBytes(Buffer<byte>.Empty);
}
else
{
Expand All @@ -171,7 +171,7 @@ public int ComputeLength()
if (_rest != null)
{
Position position = new Position();
Memory<byte> segment;
Buffer<byte> segment;
while (_rest.TryGet(ref position, out segment))
{
length += segment.Length;
Expand All @@ -186,9 +186,9 @@ public int ComputeLength()

class MemoryListNode : IMemoryList<byte>
{
internal Memory<byte> _first;
internal Buffer<byte> _first;
internal MemoryListNode _rest;
public Memory<byte> First => _first;
public Buffer<byte> First => _first;

public int? Length
{
Expand All @@ -203,7 +203,7 @@ public int CopyTo(Span<byte> buffer)
{
int copied = 0;
var position = Position.First;
Memory<byte> segment;
Buffer<byte> segment;
var free = buffer;
while (TryGet(ref position, out segment, true))
{
Expand All @@ -223,15 +223,15 @@ public int CopyTo(Span<byte> buffer)
return copied;
}

public bool TryGet(ref Position position, out Memory<byte> item, bool advance = true)
public bool TryGet(ref Position position, out Buffer<byte> item, bool advance = true)
{
if (position == Position.First)
{
item = _first;
if (advance) { position.IntegerPosition++; position.ObjectPosition = _rest; }
return true;
}
else if (position.ObjectPosition == null) { item = default(Memory<byte>); return false; }
else if (position.ObjectPosition == null) { item = default(Buffer<byte>); return false; }

var sequence = (MemoryListNode)position.ObjectPosition;
item = sequence._first;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public unsafe int Send(ReadOnlySpan<byte> buffer)
}
}

public int Send(ReadOnlyMemory<byte> buffer)
public int Send(ReadOnlyBuffer<byte> buffer)
{
return Send(buffer.Span);
}
Expand Down Expand Up @@ -202,7 +202,7 @@ public unsafe int Receive(Span<byte> buffer)
}
}

public int Receive(Memory<byte> buffer)
public int Receive(Buffer<byte> buffer)
{
return Receive(buffer.Span);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ namespace System.Buffers
{
public static class BufferExtensions
{
public static ReadOnlySpan<byte> ToSpan<T>(this T memorySequence) where T : ISequence<ReadOnlyMemory<byte>>
public static ReadOnlySpan<byte> ToSpan<T>(this T memorySequence) where T : ISequence<ReadOnlyBuffer<byte>>
{
Position position = Position.First;
ReadOnlyMemory<byte> memory;
ReadOnlyBuffer<byte> memory;
ResizableArray<byte> array = new ResizableArray<byte>(memorySequence.Length.GetValueOrDefault(1024));
while (memorySequence.TryGet(ref position, out memory))
{
Expand Down Expand Up @@ -119,7 +119,7 @@ internal static int IndexOfStraddling(this ReadOnlySpan<byte> first, IReadOnlyMe
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int IndexOf(this ReadOnlyMemory<byte> memory, ReadOnlySpan<byte> values)
public static int IndexOf(this ReadOnlyBuffer<byte> memory, ReadOnlySpan<byte> values)
{
return SpanExtensions.IndexOf(memory.Span, values);
}
Expand Down
8 changes: 4 additions & 4 deletions src/System.Buffers.Experimental/System/Buffers/BytesReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public struct BytesReader
ReadOnlyBytes _unreadSegments;
int _index; // index relative to the begining of bytes passed to the constructor

ReadOnlyMemory<byte> _currentSegment;
ReadOnlyBuffer<byte> _currentSegment;
int _currentSegmentIndex;

public BytesReader(ReadOnlyBytes bytes, TextEncoder encoder)
Expand All @@ -27,7 +27,7 @@ public BytesReader(ReadOnlyBytes bytes, TextEncoder encoder)
_index = 0;
}

public BytesReader(ReadOnlyMemory<byte> bytes, TextEncoder encoder)
public BytesReader(ReadOnlyBuffer<byte> bytes, TextEncoder encoder)
{
_unreadSegments = new ReadOnlyBytes(bytes);
_currentSegment = bytes;
Expand All @@ -36,7 +36,7 @@ public BytesReader(ReadOnlyMemory<byte> bytes, TextEncoder encoder)
_index = 0;
}

public BytesReader(ReadOnlyMemory<byte> bytes) : this(bytes, TextEncoder.Utf8)
public BytesReader(ReadOnlyBuffer<byte> bytes) : this(bytes, TextEncoder.Utf8)
{ }

public BytesReader(ReadOnlyBytes bytes) : this(bytes, TextEncoder.Utf8)
Expand Down Expand Up @@ -182,7 +182,7 @@ void AdvanceNextSegment(int count, int advancedInCurrent)
if (newSegments == null && toAdvance == 0)
{
_unreadSegments = ReadOnlyBytes.Empty;
_currentSegment = ReadOnlyMemory<byte>.Empty;
_currentSegment = ReadOnlyBuffer<byte>.Empty;
_currentSegmentIndex = 0;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
using System.Collections.Sequences;

namespace System.Buffers {
public interface IReadOnlyMemoryList<T> : ISequence<ReadOnlyMemory<T>>
public interface IReadOnlyMemoryList<T> : ISequence<ReadOnlyBuffer<T>>
{
int CopyTo(Span<T> buffer);
ReadOnlyMemory<T> First { get; }
ReadOnlyBuffer<T> First { get; }

IReadOnlyMemoryList<T> Rest { get; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected override void Dispose(bool disposing)
Marshal.FreeHGlobal(_memory);
}

public override OwnedMemory<byte> Rent(int numberOfBytes)
public override OwnedBuffer<byte> Rent(int numberOfBytes)
{
if (numberOfBytes < 1) throw new ArgumentOutOfRangeException(nameof(numberOfBytes));
if (numberOfBytes > _bufferSize) new NotSupportedException();
Expand Down Expand Up @@ -77,7 +77,7 @@ internal void Return(BufferManager pooledBuffer)
}
}

internal sealed class BufferManager : OwnedMemory<byte>
internal sealed class BufferManager : OwnedBuffer<byte>
{
private readonly NativeBufferPool _pool;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace System.Buffers
{
public class OwnedNativeMemory : OwnedMemory<byte>
public class OwnedNativeMemory : OwnedBuffer<byte>
{
public OwnedNativeMemory(int length) : this(length, Marshal.AllocHGlobal(length))
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace System.Buffers
{
// This is to support secnarios today covered by Memory<T> in corefxlab
public class OwnedPinnedArray<T> : OwnedMemory<T>
public class OwnedPinnedArray<T> : OwnedBuffer<T>
{
private GCHandle _handle;

Expand Down
Loading

0 comments on commit 536c65f

Please sign in to comment.