Skip to content
Merged
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
13 changes: 12 additions & 1 deletion src/Nethermind/Nethermind.JsonRpc/PipeReaderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Buffers;
using System.IO.Pipelines;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -15,11 +16,21 @@ public static async Task<ReadResult> ReadToEndAsync(this PipeReader reader, Canc
while (true)
{
ReadResult result = await reader.ReadAsync(cancellationToken).ConfigureAwait(false);
ReadOnlySequence<byte> buffer = result.Buffer;
if (result.IsCompleted || result.IsCanceled)
{
return result;
}

// Separate method to shrink the async state machine by not including
// the ReadOnlySequence<byte> buffer in the main method
AdvanceReaderToEnd(reader, in result);
}

[MethodImpl(MethodImplOptions.NoInlining)]
static void AdvanceReaderToEnd(PipeReader reader, in ReadResult result)
{
// Extract buffer reading to a separate method to reduce async state machine size
ReadOnlySequence<byte> buffer = result.Buffer;
reader.AdvanceTo(buffer.Start, buffer.End);
}
}
Expand Down