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
+18-27Lines changed: 18 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,6 @@
3
3
// See the LICENSE file in the project root for more information.
4
4
5
5
usingSystem;
6
-
usingSystem.Buffers;
7
6
usingSystem.Buffers.Binary;
8
7
usingSystem.Diagnostics;
9
8
usingSystem.Text;
@@ -19,8 +18,7 @@ sealed internal class SqlSequentialTextReader : System.IO.TextReader
19
18
privatereadonlyint_columnIndex;// The index of out column in the table
20
19
privatereadonlyEncoding_encoding;// Encoding for this character stream
21
20
privatereadonlyDecoder_decoder;// Decoder based on the encoding (NOTE: Decoders are stateful as they are designed to process streams of data)
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
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?)
24
22
privateint_peekedChar;// The last character that we peeked at (or -1 if we haven't peeked at anything)
25
23
privateTask_currentTask;// The current async task
26
24
privatereadonlyCancellationTokenSource_disposalTokenSource;// Used to indicate that a cancellation is requested due to disposal
@@ -359,18 +357,23 @@ private byte[] PrepareByteBuffer(int numberOfChars, out int byteBufferUsed)
// If Convert() sets completed to true, then it must have used all of the bytes we gave it
410
411
Debug.Assert(bytesUsed>=inBufferCount,"Converted completed, but not all bytes were used");
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);
412
+
_leftOverBytes=null;
422
413
}
423
414
424
415
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