Updates Pipe & Makes NetState more testable (#288)
Updates pipe eliminate result and segments from being allocated. Bumps release version
This commit is contained in:
parent
293e691539
commit
990e6fe188
14 changed files with 219 additions and 198 deletions
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
namespace System.Buffers
|
||||
{
|
||||
public readonly ref struct CircularBuffer<T> where T : struct
|
||||
public readonly ref struct CircularBuffer<T>
|
||||
{
|
||||
private readonly Span<T> _first;
|
||||
private readonly Span<T> _second;
|
||||
|
|
@ -126,5 +126,15 @@ namespace System.Buffers
|
|||
|
||||
return new CircularBuffer<T>(first, second);
|
||||
}
|
||||
|
||||
public Span<T> GetSpan(int index)
|
||||
{
|
||||
if (index < 0 || index > 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
|
||||
return index == 0 ? _first : _second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Buffers.Binary;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
|
@ -30,7 +31,7 @@ namespace Server.Network
|
|||
public int Position { get; private set; }
|
||||
public int Remaining => Length - Position;
|
||||
|
||||
public CircularBufferReader(ArraySegment<byte>[] buffers) : this(buffers[0], buffers[1])
|
||||
public CircularBufferReader(ref CircularBuffer<byte> buffer) : this(buffer.GetSpan(0), buffer.GetSpan(1))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,10 +29,6 @@ namespace System.Buffers
|
|||
public int Length { get; }
|
||||
public int Position { get; private set; }
|
||||
|
||||
public CircularBufferWriter(ArraySegment<byte>[] buffers) : this(buffers[0], buffers[1])
|
||||
{
|
||||
}
|
||||
|
||||
public CircularBufferWriter(Span<byte> first, Span<byte> second)
|
||||
{
|
||||
_first = first;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue