Skip to content

Commit 8202268

Browse files
Use Buffer.BlockCopy with byte[] (#1366)
1 parent 3b945ee commit 8202268

File tree

9 files changed

+14
-14
lines changed

9 files changed

+14
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2046,7 +2046,7 @@ private bool TryGetBytesInternal(int i, long dataIndex, byte[] buffer, int buffe
20462046
cbytes = length;
20472047
}
20482048

2049-
Array.Copy(data, ndataIndex, buffer, bufferIndex, cbytes);
2049+
Buffer.BlockCopy(data, ndataIndex, buffer, bufferIndex, cbytes);
20502050
}
20512051
catch (Exception e)
20522052
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ private void ValidateActiveOnConnection(SqlInternalConnection connection)
585585
private Guid GetGlobalTxnIdentifierFromToken()
586586
{
587587
byte[] txnGuid = new byte[16];
588-
Array.Copy(_connection.PromotedDTCToken, _globalTransactionsTokenVersionSizeInBytes /* Skip the version */, txnGuid, 0, txnGuid.Length);
588+
Buffer.BlockCopy(_connection.PromotedDTCToken, _globalTransactionsTokenVersionSizeInBytes /* Skip the version */, txnGuid, 0, txnGuid.Length);
589589
return new Guid(txnGuid);
590590
}
591591
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ private byte[] PrepareByteBuffer(int numberOfChars, out int byteBufferUsed)
372372
{
373373
// Otherwise, copy over the leftover buffer
374374
byteBuffer = new byte[byteBufferSize];
375-
Array.Copy(_leftOverBytes, byteBuffer, _leftOverBytes.Length);
375+
Buffer.BlockCopy(_leftOverBytes, 0, byteBuffer, 0,_leftOverBytes.Length);
376376
byteBufferUsed = _leftOverBytes.Length;
377377
}
378378
}
@@ -411,7 +411,7 @@ private int DecodeBytesToChars(byte[] inBuffer, int inBufferCount, char[] outBuf
411411
if ((!completed) && (bytesUsed < inBufferCount))
412412
{
413413
_leftOverBytes = new byte[inBufferCount - bytesUsed];
414-
Array.Copy(inBuffer, bytesUsed, _leftOverBytes, 0, _leftOverBytes.Length);
414+
Buffer.BlockCopy(inBuffer, bytesUsed, _leftOverBytes, 0, _leftOverBytes.Length);
415415
}
416416
else
417417
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ override public int Read(byte[] buffer, int offset, int count)
452452
cb = _cachedBytes[_currentArrayIndex].Length - _currentPosition;
453453
if (cb > count)
454454
cb = count;
455-
Array.Copy(_cachedBytes[_currentArrayIndex], _currentPosition, buffer, offset, cb);
455+
Buffer.BlockCopy(_cachedBytes[_currentArrayIndex], _currentPosition, buffer, offset, cb);
456456

457457
_currentPosition += cb;
458458
count -= (int)cb;

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SqlMetaData.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ public SqlBinary Adjust(SqlBinary value)
12851285
{
12861286
byte[] rgbValue = value.Value;
12871287
byte[] rgbNewValue = new byte[MaxLength];
1288-
Array.Copy(rgbValue, rgbNewValue, rgbValue.Length);
1288+
Buffer.BlockCopy(rgbValue, 0, rgbNewValue, 0, rgbValue.Length);
12891289
Array.Clear(rgbNewValue, rgbValue.Length, rgbNewValue.Length - rgbValue.Length);
12901290
return new SqlBinary(rgbNewValue);
12911291
}
@@ -1307,7 +1307,7 @@ public SqlBinary Adjust(SqlBinary value)
13071307
{
13081308
byte[] rgbValue = value.Value;
13091309
byte[] rgbNewValue = new byte[MaxLength];
1310-
Array.Copy(rgbValue, rgbNewValue, (int)MaxLength);
1310+
Buffer.BlockCopy(rgbValue,0, rgbNewValue,0, (int)MaxLength);
13111311
value = new SqlBinary(rgbNewValue);
13121312
}
13131313

@@ -1399,7 +1399,7 @@ public SqlBytes Adjust(SqlBytes value)
13991399
if (value.MaxLength < MaxLength)
14001400
{
14011401
byte[] rgbNew = new byte[MaxLength];
1402-
Array.Copy(value.Buffer, rgbNew, (int)oldLength);
1402+
Buffer.BlockCopy(value.Buffer, 0,rgbNew,0, (int)oldLength);
14031403
value = new SqlBytes(rgbNew);
14041404
}
14051405

@@ -1928,7 +1928,7 @@ public byte[] Adjust(byte[] value)
19281928
if (value.Length < MaxLength)
19291929
{
19301930
byte[] rgbNewValue = new byte[MaxLength];
1931-
Array.Copy(value, rgbNewValue, value.Length);
1931+
Buffer.BlockCopy(value, 0, rgbNewValue, 0, value.Length);
19321932
Array.Clear(rgbNewValue, value.Length, (int)rgbNewValue.Length - value.Length);
19331933
return rgbNewValue;
19341934
}
@@ -1949,7 +1949,7 @@ public byte[] Adjust(byte[] value)
19491949
if (value.Length > MaxLength && Max != MaxLength)
19501950
{
19511951
byte[] rgbNewValue = new byte[MaxLength];
1952-
Array.Copy(value, rgbNewValue, (int)MaxLength);
1952+
Buffer.BlockCopy(value, 0, rgbNewValue, 0, (int)MaxLength);
19531953
value = rgbNewValue;
19541954
}
19551955

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private static long GetBytesConversion(SmiEventSink_Default sink, ITypedGettersV
124124

125125
length = CheckXetParameters(metaData.SqlDbType, metaData.MaxLength * sizeof(char), value.Length,
126126
fieldOffset, buffer.Length, bufferOffset, length);
127-
Array.Copy(value.Value, checked((int)fieldOffset), buffer, bufferOffset, length);
127+
Buffer.BlockCopy(value.Value, checked((int)fieldOffset), buffer, bufferOffset, length);
128128
return length;
129129
}
130130

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private static byte[] CreateBinaryTable(SqlConnection connection, string tableNa
130130
while (position < data.Length)
131131
{
132132
int copyCount = Math.Min(pattern.Length, data.Length - position);
133-
Array.Copy(pattern, 0, data, position, copyCount);
133+
Buffer.BlockCopy(pattern, 0, data, position, copyCount);
134134
position += copyCount;
135135
}
136136

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ParameterTest/StreamInputParam.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private int ReadInternal(byte[] buffer, int offset, int count)
9393
}
9494
if (_errorPos >= _pos && _errorPos < _pos + nRead)
9595
throw new CustomStreamException();
96-
Array.Copy(_data, _pos, buffer, offset, nRead);
96+
Buffer.BlockCopy(_data, _pos, buffer, offset, nRead);
9797
_pos += nRead;
9898
return nRead;
9999
}

src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS/TDSStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public override void Write(byte[] buffer, int offset, int count)
349349
if (packetDataToWrite > 0)
350350
{
351351
// Append new data to the end of the packet data
352-
Array.Copy(buffer, bufferWrittenPosition + offset, _outgoingPacket, OutgoingPacketHeader.Length, packetDataToWrite);
352+
Buffer.BlockCopy(buffer, bufferWrittenPosition + offset, _outgoingPacket, OutgoingPacketHeader.Length, packetDataToWrite);
353353

354354
// Register that we've written new data
355355
bufferWrittenPosition += packetDataToWrite;

0 commit comments

Comments
 (0)