Skip to content

Commit

Permalink
Remove unnecessary padding
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrsongg committed Dec 3, 2024
1 parent 12fb049 commit 53984c3
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public StreamingUtf8JsonReader(Stream stream)
throw new ArgumentException("Stream must not be null. Please initialize a stream and pass it into the constructor.");

_stream = stream;
// 300 bytes of padding to acocunt for stream.read() returning more bytes than requested sometimes
_buffer = ArrayPool<byte>.Shared.Rent( (AWSConfigs.StreamingUtf8JsonReaderBufferSize ?? 4096) + 0);
_buffer = ArrayPool<byte>.Shared.Rent(AWSConfigs.StreamingUtf8JsonReaderBufferSize ?? 4096);
// need to initialize the reader even if the buffer is empty because auto-default of unassigned fields is only
// supported in C# 11+
_reader = new Utf8JsonReader(_buffer);
Expand Down Expand Up @@ -126,7 +125,7 @@ private static void GetMoreBytesFromStream(Stream stream, ref byte[] buffer, ref
resized = true;
// rent double the capacity, hopefully we never have to rent the maxValue but in case buffer.Length * 2 ends up greater
// we must protect against that
var resizedBuffer = ArrayPool<byte>.Shared.Rent(Math.Min(int.MaxValue, (buffer.Length * 2) + 0));
var resizedBuffer = ArrayPool<byte>.Shared.Rent(Math.Min(int.MaxValue, (buffer.Length * 2)));
Logger.GetLogger(typeof(StreamingUtf8JsonReader)).InfoFormat("Resizing buffer from {0} to {1}", buffer.Length, resizedBuffer.Length);

buffer.AsSpan().CopyTo(resizedBuffer);
Expand Down

0 comments on commit 53984c3

Please sign in to comment.