Skip to content

Commit f5e1845

Browse files
committed
review feedback, add local for char size
1 parent 689e904 commit f5e1845

File tree

2 files changed

+11
-9
lines changed
  • src/Microsoft.Data.SqlClient

2 files changed

+11
-9
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13167,14 +13167,15 @@ bool writeDataSizeToSnapshot
1316713167
// later needing to repeatedly allocate new target buffers and copy data as we discover new data
1316813168
if (buff == null && stateObj._longlen != TdsEnums.SQL_PLP_UNKNOWNLEN && stateObj._longlen < (int.MaxValue >> 1))
1316913169
{
13170-
if (supportRentedBuff && stateObj._longlen >> 1 < 1073741824) // 1 Gib
13170+
int stateLen = (int)stateObj._longlen >> 1;
13171+
if (supportRentedBuff && stateLen < 1073741824) // 1 Gib
1317113172
{
13172-
buff = ArrayPool<char>.Shared.Rent((int)Math.Min((int)stateObj._longlen >> 1, len));
13173+
buff = ArrayPool<char>.Shared.Rent(Math.Min(stateLen, len));
1317313174
rentedBuff = true;
1317413175
}
1317513176
else
1317613177
{
13177-
buff = new char[(int)Math.Min((int)stateObj._longlen >> 1, len)];
13178+
buff = new char[Math.Min(stateLen, len)];
1317813179
rentedBuff = false;
1317913180
}
1318013181
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13322,19 +13322,20 @@ bool writeDataSizeToSnapshot
1332213322
);
1332313323
charsLeft = len;
1332413324

13325-
// If total length is known up front, the length isn't specified as unknown
13326-
// and the caller doesn't pass int.max/2 indicating that it doesn't know the length
13327-
// allocate the whole buffer in one shot instead of realloc'ing and copying over each time
13325+
// If total data length is known up front from the plp header by being not SQL_PLP_UNKNOWNLEN
13326+
// and the number of chars required is less than int.max/2 allocate the entire buffer now to avoid
13327+
// later needing to repeatedly allocate new target buffers and copy data as we discover new data
1332813328
if (buff == null && stateObj._longlen != TdsEnums.SQL_PLP_UNKNOWNLEN && stateObj._longlen < (int.MaxValue >> 1))
1332913329
{
13330-
if (supportRentedBuff && stateObj._longlen >> 1 < 1073741824) // 1 Gib
13330+
int stateLen = (int)stateObj._longlen >> 1;
13331+
if (supportRentedBuff && stateLen < 1073741824) // 1 Gib
1333113332
{
13332-
buff = ArrayPool<char>.Shared.Rent((int)Math.Min((int)stateObj._longlen >> 1, len));
13333+
buff = ArrayPool<char>.Shared.Rent(Math.Min(stateLen, len));
1333313334
rentedBuff = true;
1333413335
}
1333513336
else
1333613337
{
13337-
buff = new char[(int)Math.Min((int)stateObj._longlen >> 1, len)];
13338+
buff = new char[Math.Min(stateLen, len)];
1333813339
rentedBuff = false;
1333913340
}
1334013341
}

0 commit comments

Comments
 (0)