File tree Expand file tree Collapse file tree 2 files changed +11
-9
lines changed
src/Microsoft.Data.SqlClient
netcore/src/Microsoft/Data/SqlClient
netfx/src/Microsoft/Data/SqlClient Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -13171,14 +13171,15 @@ bool writeDataSizeToSnapshot
1317113171 // later needing to repeatedly allocate new target buffers and copy data as we discover new data
1317213172 if (buff == null && stateObj._longlen != TdsEnums.SQL_PLP_UNKNOWNLEN && stateObj._longlen < (int.MaxValue >> 1))
1317313173 {
13174- if (supportRentedBuff && stateObj._longlen >> 1 < 1073741824) // 1 Gib
13174+ int stateLen = (int)stateObj._longlen >> 1;
13175+ if (supportRentedBuff && stateLen < 1073741824) // 1 Gib
1317513176 {
13176- buff = ArrayPool<char>.Shared.Rent((int) Math.Min((int)stateObj._longlen >> 1 , len));
13177+ buff = ArrayPool<char>.Shared.Rent(Math.Min(stateLen , len));
1317713178 rentedBuff = true;
1317813179 }
1317913180 else
1318013181 {
13181- buff = new char[(int) Math.Min((int)stateObj._longlen >> 1 , len)];
13182+ buff = new char[Math.Min(stateLen , len)];
1318213183 rentedBuff = false;
1318313184 }
1318413185 }
Original file line number Diff line number Diff line change @@ -13327,19 +13327,20 @@ bool writeDataSizeToSnapshot
1332713327 );
1332813328 charsLeft = len;
1332913329
13330- // If total length is known up front, the length isn't specified as unknown
13331- // and the caller doesn't pass int.max/2 indicating that it doesn't know the length
13332- // allocate the whole buffer in one shot instead of realloc'ing and copying over each time
13330+ // If total data length is known up front from the plp header by being not SQL_PLP_UNKNOWNLEN
13331+ // and the number of chars required is less than int.max/2 allocate the entire buffer now to avoid
13332+ // later needing to repeatedly allocate new target buffers and copy data as we discover new data
1333313333 if (buff == null && stateObj._longlen != TdsEnums.SQL_PLP_UNKNOWNLEN && stateObj._longlen < (int.MaxValue >> 1))
1333413334 {
13335- if (supportRentedBuff && stateObj._longlen >> 1 < 1073741824) // 1 Gib
13335+ int stateLen = (int)stateObj._longlen >> 1;
13336+ if (supportRentedBuff && stateLen < 1073741824) // 1 Gib
1333613337 {
13337- buff = ArrayPool<char>.Shared.Rent((int) Math.Min((int)stateObj._longlen >> 1 , len));
13338+ buff = ArrayPool<char>.Shared.Rent(Math.Min(stateLen , len));
1333813339 rentedBuff = true;
1333913340 }
1334013341 else
1334113342 {
13342- buff = new char[(int) Math.Min((int)stateObj._longlen >> 1 , len)];
13343+ buff = new char[Math.Min(stateLen , len)];
1334313344 rentedBuff = false;
1334413345 }
1334513346 }
You can’t perform that action at this time.
0 commit comments