Skip to content

Commit 662d8ac

Browse files
committed
Replace Array.Copy with Buffer.BlockCopy.
See discussion at dotnet/corefx#6103.
1 parent f59c6d8 commit 662d8ac

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/MySql.Data/ByteArrayReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public byte[] ReadNullTerminatedByteString()
111111
if (index == m_maxOffset)
112112
throw new FormatException("Read past end of buffer looking for NUL.");
113113
byte[] substring = new byte[index - m_offset];
114-
Array.Copy(m_buffer, m_offset, substring, 0, substring.Length);
114+
Buffer.BlockCopy(m_buffer, m_offset, substring, 0, substring.Length);
115115
m_offset = index + 1;
116116
return substring;
117117
}
@@ -120,7 +120,7 @@ public byte[] ReadByteString(int length)
120120
{
121121
VerifyRead(length);
122122
var result = new byte[length];
123-
Array.Copy(m_buffer, m_offset, result, 0, result.Length);
123+
Buffer.BlockCopy(m_buffer, m_offset, result, 0, result.Length);
124124
m_offset += length;
125125
return result;
126126
}

src/MySql.Data/MySqlClient/MySqlDataReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public override long GetBytes(int ordinal, long dataOffset, byte[] buffer, int b
136136
throw new ArgumentException("bufferOffset + length cannot exceed buffer.Length", nameof(length));
137137

138138
int lengthToCopy = Math.Min(m_dataLengths[ordinal] - (int) dataOffset, length);
139-
Array.Copy(m_currentRow, checked((int) (m_dataOffsets[ordinal] + dataOffset)), buffer, bufferOffset, lengthToCopy);
139+
Buffer.BlockCopy(m_currentRow, checked((int) (m_dataOffsets[ordinal] + dataOffset)), buffer, bufferOffset, lengthToCopy);
140140
return lengthToCopy;
141141
}
142142

@@ -399,7 +399,7 @@ public override object GetValue(int ordinal)
399399
if (columnDefinition.CharacterSet == CharacterSet.Binary)
400400
{
401401
var result = new byte[m_dataLengths[ordinal]];
402-
Array.Copy(m_currentRow, m_dataOffsets[ordinal], result, 0, result.Length);
402+
Buffer.BlockCopy(m_currentRow, m_dataOffsets[ordinal], result, 0, result.Length);
403403
return Connection.OldGuids && columnDefinition.ColumnLength == 16 ? (object) new Guid(result) : result;
404404
}
405405
return Encoding.UTF8.GetString(data);

src/MySql.Data/Serialization/AuthenticationUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ public static byte[] HashPassword(byte[] challenge, int offset, string password)
1919
using (var sha1 = SHA1.Create())
2020
{
2121
var combined = new byte[40];
22-
Array.Copy(challenge, offset, combined, 0, 20);
22+
Buffer.BlockCopy(challenge, offset, combined, 0, 20);
2323

2424
var passwordBytes = Encoding.UTF8.GetBytes(password);
2525
var hashedPassword = sha1.ComputeHash(passwordBytes);
2626

2727
var doubleHashedPassword = sha1.ComputeHash(hashedPassword);
28-
Array.Copy(doubleHashedPassword, 0, combined, 20, 20);
28+
Buffer.BlockCopy(doubleHashedPassword, 0, combined, 20, 20);
2929

3030
var xorBytes = sha1.ComputeHash(combined);
3131
for (int i = 0; i < hashedPassword.Length; i++)

src/MySql.Data/Serialization/InitialHandshakePacket.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ internal InitialHandshakePacket(ByteArrayReader reader)
3131
{
3232
var authPluginData2 = reader.ReadByteString(Math.Max(13, authPluginDataLength - 8));
3333
var concatenated = new byte[AuthPluginData.Length + authPluginData2.Length];
34-
Array.Copy(AuthPluginData, concatenated, AuthPluginData.Length);
35-
Array.Copy(authPluginData2, 0, concatenated, AuthPluginData.Length, authPluginData2.Length);
34+
Buffer.BlockCopy(AuthPluginData, 0, concatenated, 0, AuthPluginData.Length);
35+
Buffer.BlockCopy(authPluginData2, 0, concatenated, AuthPluginData.Length, authPluginData2.Length);
3636
AuthPluginData = concatenated;
3737
}
3838
if (ProtocolCapabilities.HasFlag(ProtocolCapabilities.PluginAuth))

src/MySql.Data/Serialization/PacketTransmitter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private async Task DoSendAsync(PayloadData payload, CancellationToken cancellati
6363

6464
if (bytesToSend <= m_buffer.Length - 4)
6565
{
66-
Array.Copy(data.Array, data.Offset, m_buffer, 4, bytesToSend);
66+
Buffer.BlockCopy(data.Array, data.Offset, m_buffer, 4, bytesToSend);
6767
m_socketAwaitable.EventArgs.SetBuffer(0, bytesToSend + 4);
6868
await m_socket.SendAsync(m_socketAwaitable);
6969
}
@@ -85,7 +85,7 @@ private async Task<PayloadData> DoReceiveAsync(CancellationToken cancellationTok
8585
if (m_end - m_offset < 4)
8686
{
8787
if (m_end - m_offset > 0)
88-
Array.Copy(m_buffer, m_offset, m_buffer, 0, m_end - m_offset);
88+
Buffer.BlockCopy(m_buffer, m_offset, m_buffer, 0, m_end - m_offset);
8989
m_end -= m_offset;
9090
m_offset = 0;
9191
}
@@ -140,7 +140,7 @@ private async Task<PayloadData> DoReceiveAsync(CancellationToken cancellationTok
140140
var readData = m_buffer;
141141
if (payloadLength > m_buffer.Length)
142142
readData = new byte[payloadLength];
143-
Array.Copy(m_buffer, m_offset, readData, 0, m_end - m_offset);
143+
Buffer.BlockCopy(m_buffer, m_offset, readData, 0, m_end - m_offset);
144144
m_socketAwaitable.EventArgs.SetBuffer(readData, 0, 0);
145145

146146
// read payload

0 commit comments

Comments
 (0)