Skip to content

Commit 671580c

Browse files
committed
address review feedback
1 parent cd6d360 commit 671580c

File tree

3 files changed

+75
-80
lines changed

3 files changed

+75
-80
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDataReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3766,7 +3766,7 @@ private TdsOperationStatus TryNextResult(out bool more)
37663766
if (result != TdsOperationStatus.Done)
37673767
{
37683768
more = false;
3769-
return TdsOperationStatus.Done;
3769+
return result;
37703770
}
37713771

37723772
// In the case of not closing the reader, null out the metadata AFTER

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13070,56 +13070,53 @@ bool writeDataSizeToSnapshot
1307013070

1307113071
while (charsLeft > 0)
1307213072
{
13073-
if (partialReadInProgress)
13073+
if (!partialReadInProgress)
1307413074
{
13075-
goto resumePartialRead;
13076-
}
13077-
charsRead = (int)Math.Min((stateObj._longlenleft + 1) >> 1, (ulong)charsLeft);
13078-
if ((buff == null) || (buff.Length < (offst + charsRead)))
13079-
{
13080-
char[] newbuf;
13081-
bool returnRentedBufferAfterCopy = rentedBuff;
13082-
if (supportRentedBuff && (offst + charsRead) < 1073741824) // 1 Gib
13083-
{
13084-
newbuf = ArrayPool<char>.Shared.Rent(offst + charsRead);
13085-
rentedBuff = true;
13086-
}
13087-
else
13075+
charsRead = (int)Math.Min((stateObj._longlenleft + 1) >> 1, (ulong)charsLeft);
13076+
if ((buff == null) || (buff.Length < (offst + charsRead)))
1308813077
{
13089-
newbuf = new char[offst + charsRead];
13090-
rentedBuff = false;
13091-
}
13078+
char[] newbuf;
13079+
bool returnRentedBufferAfterCopy = rentedBuff;
13080+
if (supportRentedBuff && (offst + charsRead) < 1073741824) // 1 Gib
13081+
{
13082+
newbuf = ArrayPool<char>.Shared.Rent(offst + charsRead);
13083+
rentedBuff = true;
13084+
}
13085+
else
13086+
{
13087+
newbuf = new char[offst + charsRead];
13088+
rentedBuff = false;
13089+
}
1309213090

13093-
if (buff != null)
13094-
{
13095-
Buffer.BlockCopy(buff, 0, newbuf, 0, offst * 2);
13096-
if (returnRentedBufferAfterCopy)
13091+
if (buff != null)
1309713092
{
13098-
buff.AsSpan(0, offst).Clear();
13099-
ArrayPool<char>.Shared.Return(buff, clearArray: false);
13093+
Buffer.BlockCopy(buff, 0, newbuf, 0, offst * 2);
13094+
if (returnRentedBufferAfterCopy)
13095+
{
13096+
buff.AsSpan(0, offst).Clear();
13097+
ArrayPool<char>.Shared.Return(buff, clearArray: false);
13098+
}
1310013099
}
13100+
buff = newbuf;
13101+
newbuf = null;
1310113102
}
13102-
buff = newbuf;
13103-
newbuf = null;
13104-
}
13105-
if (charsRead > 0)
13106-
{
13107-
result = TryReadPlpUnicodeCharsChunk(buff, offst, charsRead, stateObj, out charsRead);
13108-
if (result != TdsOperationStatus.Done)
13103+
if (charsRead > 0)
1310913104
{
13110-
return result;
13111-
}
13112-
charsLeft -= charsRead;
13113-
offst += charsRead;
13114-
totalCharsRead += charsRead;
13105+
result = TryReadPlpUnicodeCharsChunk(buff, offst, charsRead, stateObj, out charsRead);
13106+
if (result != TdsOperationStatus.Done)
13107+
{
13108+
return result;
13109+
}
13110+
charsLeft -= charsRead;
13111+
offst += charsRead;
13112+
totalCharsRead += charsRead;
1311513113

13116-
if (writeDataSizeToSnapshot)
13117-
{
13118-
currentPacketId = IncrementSnapshotDataSize(stateObj, restartingDataSizeCount, currentPacketId, charsRead * 2);
13114+
if (writeDataSizeToSnapshot)
13115+
{
13116+
currentPacketId = IncrementSnapshotDataSize(stateObj, restartingDataSizeCount, currentPacketId, charsRead * 2);
13117+
}
1311913118
}
1312013119
}
13121-
13122-
resumePartialRead:
1312313120
// Special case single byte
1312413121
if (
1312513122
(stateObj._longlenleft == 1 || partialReadInProgress)

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13613,56 +13613,54 @@ bool writeDataSizeToSnapshot
1361313613

1361413614
while (charsLeft > 0)
1361513615
{
13616-
if (partialReadInProgress)
13616+
if (!partialReadInProgress)
1361713617
{
13618-
goto resumePartialRead;
13619-
}
13620-
charsRead = (int)Math.Min((stateObj._longlenleft + 1) >> 1, (ulong)charsLeft);
13621-
if ((buff == null) || (buff.Length < (offst + charsRead)))
13622-
{
13623-
char[] newbuf;
13624-
bool returnRentedBufferAfterCopy = rentedBuff;
13625-
if (supportRentedBuff && (offst + charsRead) < 1073741824) // 1 Gib
13618+
charsRead = (int)Math.Min((stateObj._longlenleft + 1) >> 1, (ulong)charsLeft);
13619+
if ((buff == null) || (buff.Length < (offst + charsRead)))
1362613620
{
13627-
newbuf = ArrayPool<char>.Shared.Rent(offst + charsRead);
13628-
rentedBuff = true;
13629-
}
13630-
else
13631-
{
13632-
newbuf = new char[offst + charsRead];
13633-
rentedBuff = false;
13634-
}
13621+
char[] newbuf;
13622+
bool returnRentedBufferAfterCopy = rentedBuff;
13623+
if (supportRentedBuff && (offst + charsRead) < 1073741824) // 1 Gib
13624+
{
13625+
newbuf = ArrayPool<char>.Shared.Rent(offst + charsRead);
13626+
rentedBuff = true;
13627+
}
13628+
else
13629+
{
13630+
newbuf = new char[offst + charsRead];
13631+
rentedBuff = false;
13632+
}
1363513633

13636-
if (buff != null)
13637-
{
13638-
Buffer.BlockCopy(buff, 0, newbuf, 0, offst * 2);
13639-
if (returnRentedBufferAfterCopy)
13634+
if (buff != null)
1364013635
{
13641-
buff.AsSpan(0, offst).Clear();
13642-
ArrayPool<char>.Shared.Return(buff, clearArray: false);
13636+
Buffer.BlockCopy(buff, 0, newbuf, 0, offst * 2);
13637+
if (returnRentedBufferAfterCopy)
13638+
{
13639+
buff.AsSpan(0, offst).Clear();
13640+
ArrayPool<char>.Shared.Return(buff, clearArray: false);
13641+
}
1364313642
}
13643+
buff = newbuf;
13644+
newbuf = null;
1364413645
}
13645-
buff = newbuf;
13646-
newbuf = null;
13647-
}
13648-
if (charsRead > 0)
13649-
{
13650-
result = TryReadPlpUnicodeCharsChunk(buff, offst, charsRead, stateObj, out charsRead);
13651-
if (result != TdsOperationStatus.Done)
13646+
if (charsRead > 0)
1365213647
{
13653-
return result;
13654-
}
13655-
charsLeft -= charsRead;
13656-
offst += charsRead;
13657-
totalCharsRead += charsRead;
13648+
result = TryReadPlpUnicodeCharsChunk(buff, offst, charsRead, stateObj, out charsRead);
13649+
if (result != TdsOperationStatus.Done)
13650+
{
13651+
return result;
13652+
}
13653+
charsLeft -= charsRead;
13654+
offst += charsRead;
13655+
totalCharsRead += charsRead;
1365813656

13659-
if (writeDataSizeToSnapshot)
13660-
{
13661-
currentPacketId = IncrementSnapshotDataSize(stateObj, restartingDataSizeCount, currentPacketId, charsRead * 2);
13657+
if (writeDataSizeToSnapshot)
13658+
{
13659+
currentPacketId = IncrementSnapshotDataSize(stateObj, restartingDataSizeCount, currentPacketId, charsRead * 2);
13660+
}
1366213661
}
1366313662
}
1366413663

13665-
resumePartialRead:
1366613664
// Special case single byte
1366713665
if (
1366813666
(stateObj._longlenleft == 1 || partialReadInProgress )

0 commit comments

Comments
 (0)