From e3114ba567b4ea5daa70428e17376511176d49e4 Mon Sep 17 00:00:00 2001 From: Plerx <50530305+Plerx2493@users.noreply.github.com> Date: Thu, 9 Apr 2026 23:06:48 +0200 Subject: [PATCH] Add sizeHint to `GetSpan` in BuffersExtensions --- .../System.Memory/src/System/Buffers/BuffersExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Memory/src/System/Buffers/BuffersExtensions.cs b/src/libraries/System.Memory/src/System/Buffers/BuffersExtensions.cs index 080c50a0650604..ce62c9cec04bf8 100644 --- a/src/libraries/System.Memory/src/System/Buffers/BuffersExtensions.cs +++ b/src/libraries/System.Memory/src/System/Buffers/BuffersExtensions.cs @@ -115,7 +115,7 @@ public static T[] ToArray(in this ReadOnlySequence sequence) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Write(this IBufferWriter writer, ReadOnlySpan value) { - Span destination = writer.GetSpan(); + Span destination = writer.GetSpan(value.Length); // Fast path, try copying to the available memory directly if (value.Length <= destination.Length) @@ -140,7 +140,7 @@ private static void WriteMultiSegment(IBufferWriter writer, in ReadOnlySpa input = input.Slice(writeSize); if (input.Length > 0) { - destination = writer.GetSpan(); + destination = writer.GetSpan(input.Length); if (destination.IsEmpty) {