From a429c5ed2f748942cea30e1904f7d2553bc7ab85 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 21 Nov 2024 08:34:09 -0500 Subject: [PATCH] Fix BufferExtensions.Write to specify sizeHint to GetSpan --- .../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 080c50a065060..ce62c9cec04bf 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) {