Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static T[] ToArray<T>(in this ReadOnlySequence<T> sequence)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Write<T>(this IBufferWriter<T> writer, ReadOnlySpan<T> value)
{
Span<T> destination = writer.GetSpan();
Span<T> destination = writer.GetSpan(value.Length);

// Fast path, try copying to the available memory directly
Comment on lines 116 to 120
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change alters the observable behavior of Write for writers that allocate based on sizeHint (e.g., the existing TestBufferWriterMultiSegment in System.Memory tests). With GetSpan(value.Length) / GetSpan(input.Length), those tests will no longer write one byte per segment (they'll typically write the whole span in a single segment), so current assertions like Comitted.Count == 12 will fail. Please update/add tests to validate the new contract (that the sizeHint passed equals the remaining input length) rather than relying on the old sizeHint == 0 growth behavior.

Copilot uses AI. Check for mistakes.
if (value.Length <= destination.Length)
Expand All @@ -140,7 +140,7 @@ private static void WriteMultiSegment<T>(IBufferWriter<T> writer, in ReadOnlySpa
input = input.Slice(writeSize);
if (input.Length > 0)
{
destination = writer.GetSpan();
destination = writer.GetSpan(input.Length);

if (destination.IsEmpty)
{
Expand Down
Loading