You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlSequentialTextReader.cs
+27-18Lines changed: 27 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@
3
3
// See the LICENSE file in the project root for more information.
4
4
5
5
usingSystem;
6
+
usingSystem.Buffers;
6
7
usingSystem.Buffers.Binary;
7
8
usingSystem.Diagnostics;
8
9
usingSystem.Text;
@@ -18,7 +19,8 @@ sealed internal class SqlSequentialTextReader : System.IO.TextReader
18
19
privatereadonlyint_columnIndex;// The index of out column in the table
19
20
privatereadonlyEncoding_encoding;// Encoding for this character stream
20
21
privatereadonlyDecoder_decoder;// Decoder based on the encoding (NOTE: Decoders are stateful as they are designed to process streams of data)
21
-
privatebyte[]_leftOverBytes;// Bytes leftover from the last Read() operation - this can be null if there were no bytes leftover (Possible optimization: re-use the same array?)
22
+
privatebyte[]_leftOverBytes;// Bytes leftover from the last Read() operation - this can be null if there were no bytes leftover
23
+
privateint_leftOverByteBufferUsed;//Number of bytes used from _leftOverBytes buffer - will be zero in case of null buffer
22
24
privateint_peekedChar;// The last character that we peeked at (or -1 if we haven't peeked at anything)
23
25
privateTask_currentTask;// The current async task
24
26
privatereadonlyCancellationTokenSource_disposalTokenSource;// Used to indicate that a cancellation is requested due to disposal
@@ -357,23 +359,18 @@ private byte[] PrepareByteBuffer(int numberOfChars, out int byteBufferUsed)
357
359
358
360
if(_leftOverBytes!=null)
359
361
{
360
-
// If we have more leftover bytes than we need for this conversion, then just re-use the leftover buffer
// If Convert() sets completed to true, then it must have used all of the bytes we gave it
411
410
Debug.Assert(bytesUsed>=inBufferCount,"Converted completed, but not all bytes were used");
412
-
_leftOverBytes=null;
411
+
if(_leftOverBytes!=null)
412
+
{
413
+
ArrayPool<byte>.Shared.Return(_leftOverBytes);
414
+
_leftOverBytes=null;
415
+
_leftOverByteBufferUsed=0;
416
+
}
417
+
}
418
+
419
+
if(inBuffer.Length>0)
420
+
{
421
+
ArrayPool<byte>.Shared.Return(inBuffer);
413
422
}
414
423
415
424
Debug.Assert(((_reader==null)||(_reader.ColumnDataBytesRemaining()>0)||(!completed)||(_leftOverBytes==null)),"Stream has run out of data and the decoder finished, but there are leftover bytes");
0 commit comments