Skip to content

Commit 51edc67

Browse files
committed
Use Buffer.BlockCopy with byte[]
In particular after dotnet/coreclr#3118, Buffer.BlockCopy has less overhead than Array.Copy when copying byte[]s, such that there's no benefit to using Array.Copy and potential benefit to using Buffer.BlockCopy. This commit replaces usage of Array.Copy(byte[], ...) in corefx with Buffer.BlockCopy(byte[], ...). A lot of places were already using it. (In a few places where we weren't passing lower bounds to Array.Copy with T[] arguments, I added explicit lower bounds as well to avoid the overload needing to call GetLowerBound.)
1 parent 2cfbb08 commit 51edc67

File tree

34 files changed

+61
-61
lines changed

34 files changed

+61
-61
lines changed

src/Common/src/System/Net/Logging/GlobalLog.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public static void Dump(byte[] buffer, int offset, int length)
248248
}
249249

250250
var bufferSegment = new byte[length];
251-
Array.Copy(buffer, offset, bufferSegment, 0, length);
251+
Buffer.BlockCopy(buffer, offset, bufferSegment, 0, length);
252252
EventSourceLogging.Log.DebugDumpArray(bufferSegment);
253253
}
254254

src/Common/src/System/Security/Cryptography/RSAOpenSsl.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public override byte[] Decrypt(byte[] data, RSAEncryptionPadding padding)
108108
}
109109

110110
byte[] plainBytes = new byte[returnValue];
111-
Array.Copy(buf, 0, plainBytes, 0, returnValue);
111+
Buffer.BlockCopy(buf, 0, plainBytes, 0, returnValue);
112112
return plainBytes;
113113
}
114114

src/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/SymbolManagerBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public TypeArray AllocParams(params CType[] types)
400400
public TypeArray ConcatParams(CType[] prgtype1, CType[] prgtype2)
401401
{
402402
CType[] combined = new CType[prgtype1.Length + prgtype2.Length];
403-
Array.Copy(prgtype1, combined, prgtype1.Length);
403+
Array.Copy(prgtype1, 0, combined, 0, prgtype1.Length);
404404
Array.Copy(prgtype2, 0, combined, prgtype1.Length, prgtype2.Length);
405405
return AllocParams(combined);
406406
}

src/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/UIHintAttribute.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public UIHintImplementation(string uiHint, string presentationLayer, params obje
100100
if (controlParameters != null)
101101
{
102102
_inputControlParameters = new object[controlParameters.Length];
103-
Array.Copy(controlParameters, _inputControlParameters, controlParameters.Length);
103+
Array.Copy(controlParameters, 0, _inputControlParameters, 0, controlParameters.Length);
104104
}
105105
}
106106

src/System.Data.SqlClient/src/System/Data/Common/DataRecordInternal.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public override long GetBytes(int i, long dataIndex, byte[] buffer, int bufferIn
143143
}
144144

145145
// until arrays are 64 bit, we have to do these casts
146-
Array.Copy(data, ndataIndex, buffer, bufferIndex, (int)cbytes);
146+
Buffer.BlockCopy(data, ndataIndex, buffer, bufferIndex, (int)cbytes);
147147
}
148148
catch (Exception e)
149149
{

src/System.Data.SqlClient/src/System/Data/Sql/SqlMetaData.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ public SqlBinary Adjust(SqlBinary value)
942942
{
943943
byte[] rgbValue = value.Value;
944944
byte[] rgbNewValue = new byte[MaxLength];
945-
Array.Copy(rgbValue, 0, rgbNewValue, 0, rgbValue.Length);
945+
Buffer.BlockCopy(rgbValue, 0, rgbNewValue, 0, rgbValue.Length);
946946
Array.Clear(rgbNewValue, rgbValue.Length, rgbNewValue.Length - rgbValue.Length);
947947
return new SqlBinary(rgbNewValue);
948948
}
@@ -963,7 +963,7 @@ public SqlBinary Adjust(SqlBinary value)
963963
{
964964
byte[] rgbValue = value.Value;
965965
byte[] rgbNewValue = new byte[MaxLength];
966-
Array.Copy(rgbValue, 0, rgbNewValue, 0, (int)MaxLength);
966+
Buffer.BlockCopy(rgbValue, 0, rgbNewValue, 0, (int)MaxLength);
967967
value = new SqlBinary(rgbNewValue);
968968
}
969969

@@ -1040,7 +1040,7 @@ public SqlBytes Adjust(SqlBytes value)
10401040
if (value.MaxLength < MaxLength)
10411041
{
10421042
byte[] rgbNew = new byte[MaxLength];
1043-
Array.Copy(value.Buffer, 0, rgbNew, 0, (int)oldLength);
1043+
Buffer.BlockCopy(value.Buffer, 0, rgbNew, 0, (int)oldLength);
10441044
value = new SqlBytes(rgbNew);
10451045
}
10461046

@@ -1380,7 +1380,7 @@ public byte[] Adjust(byte[] value)
13801380
if (value.Length < MaxLength)
13811381
{
13821382
byte[] rgbNewValue = new byte[MaxLength];
1383-
Array.Copy(value, 0, rgbNewValue, 0, value.Length);
1383+
Buffer.BlockCopy(value, 0, rgbNewValue, 0, value.Length);
13841384
Array.Clear(rgbNewValue, value.Length, (int)rgbNewValue.Length - value.Length);
13851385
return rgbNewValue;
13861386
}
@@ -1400,7 +1400,7 @@ public byte[] Adjust(byte[] value)
14001400
if (value.Length > MaxLength && Max != MaxLength)
14011401
{
14021402
byte[] rgbNewValue = new byte[MaxLength];
1403-
Array.Copy(value, 0, rgbNewValue, 0, (int)MaxLength);
1403+
Buffer.BlockCopy(value, 0, rgbNewValue, 0, (int)MaxLength);
14041404
value = rgbNewValue;
14051405
}
14061406

src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SNIPacket.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public SNIPacket Clone()
124124
{
125125
SNIPacket packet = new SNIPacket(null);
126126
packet._data = new byte[_length];
127-
Array.Copy(_data, 0, packet._data, 0, _length);
127+
Buffer.BlockCopy(_data, 0, packet._data, 0, _length);
128128
packet._length = _length;
129129

130130
return packet;

src/System.Data.SqlClient/src/System/Data/SqlClient/SqlDataReader.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ private bool TryGetBytesInternal(int i, long dataIndex, byte[] buffer, int buffe
13741374
cbytes = length;
13751375
}
13761376

1377-
Array.Copy(data, ndataIndex, buffer, bufferIndex, cbytes);
1377+
Buffer.BlockCopy(data, ndataIndex, buffer, bufferIndex, cbytes);
13781378
}
13791379
catch (Exception e)
13801380
{

src/System.Data.SqlClient/src/System/Data/SqlClient/SqlSequentialTextReader.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ private byte[] PrepareByteBuffer(int numberOfChars, out int byteBufferUsed)
371371
{
372372
// Otherwise, copy over the leftover buffer
373373
byteBuffer = new byte[byteBufferSize];
374-
Array.Copy(_leftOverBytes, byteBuffer, _leftOverBytes.Length);
374+
Buffer.BlockCopy(_leftOverBytes, 0, byteBuffer, 0, _leftOverBytes.Length);
375375
byteBufferUsed = _leftOverBytes.Length;
376376
}
377377
}
@@ -410,7 +410,7 @@ private int DecodeBytesToChars(byte[] inBuffer, int inBufferCount, char[] outBuf
410410
if ((!completed) && (bytesUsed < inBufferCount))
411411
{
412412
_leftOverBytes = new byte[inBufferCount - bytesUsed];
413-
Array.Copy(inBuffer, bytesUsed, _leftOverBytes, 0, _leftOverBytes.Length);
413+
Buffer.BlockCopy(inBuffer, bytesUsed, _leftOverBytes, 0, _leftOverBytes.Length);
414414
}
415415
else
416416
{

src/System.Data.SqlClient/src/System/Data/SqlClient/SqlStream.cs

+1-1
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/System.Data.SqlClient/src/System/Data/SqlTypes/SQLBytes.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public byte[] Value
194194

195195
default:
196196
buffer = new byte[_lCurLen];
197-
Array.Copy(m_rgbBuf, buffer, (int)_lCurLen);
197+
Buffer.BlockCopy(m_rgbBuf, 0, buffer, 0, (int)_lCurLen);
198198
break;
199199
}
200200

@@ -343,7 +343,7 @@ public long Read(long offset, byte[] buffer, int offsetInBuffer, int count)
343343
default:
344344
// ProjectK\Core doesn't support long-typed array indexers
345345
Debug.Assert(offset < int.MaxValue);
346-
Array.Copy(m_rgbBuf, checked((int)offset), buffer, offsetInBuffer, count);
346+
Buffer.BlockCopy(m_rgbBuf, checked((int)offset), buffer, offsetInBuffer, count);
347347
break;
348348
}
349349
}
@@ -409,7 +409,7 @@ public void Write(long offset, byte[] buffer, int offsetInBuffer, int count)
409409
{
410410
// ProjectK\Core doesn't support long-typed array indexers
411411
Debug.Assert(offset < int.MaxValue);
412-
Array.Copy(buffer, offsetInBuffer, m_rgbBuf, checked((int)offset), count);
412+
Buffer.BlockCopy(buffer, offsetInBuffer, m_rgbBuf, checked((int)offset), count);
413413

414414
// If the last position that has been written is after
415415
// the current data length, reset the length

src/System.Data.SqlClient/src/System/Data/SqlTypes/SQLChars.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public char[] Value
186186

187187
default:
188188
buffer = new char[_lCurLen];
189-
Array.Copy(m_rgchBuf, buffer, (int)_lCurLen);
189+
Array.Copy(m_rgchBuf, 0, buffer, 0, (int)_lCurLen);
190190
break;
191191
}
192192

src/System.Diagnostics.Tracing/src/System/Diagnostics/Tracing/EventCounter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ private static void EnsureEventSourceIndexAvailable(int eventSourceIndex)
285285
else if (eventSourceIndex >= EventCounterGroup.s_eventCounterGroups.Length)
286286
{
287287
EventCounterGroup[] newEventCounterGroups = new EventCounterGroup[eventSourceIndex + 1];
288-
Array.Copy(EventCounterGroup.s_eventCounterGroups, newEventCounterGroups, EventCounterGroup.s_eventCounterGroups.Length);
288+
Array.Copy(EventCounterGroup.s_eventCounterGroups, 0, newEventCounterGroups, 0, EventCounterGroup.s_eventCounterGroups.Length);
289289
EventCounterGroup.s_eventCounterGroups = newEventCounterGroups;
290290
}
291291
}

src/System.Diagnostics.Tracing/src/System/Diagnostics/Tracing/EventSource.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3645,7 +3645,7 @@ private static void AddEventDescriptor(ref EventMetadata[] eventData, string eve
36453645
if (eventData == null || eventData.Length <= eventAttribute.EventId)
36463646
{
36473647
EventMetadata[] newValues = new EventMetadata[Math.Max(eventData.Length + 16, eventAttribute.EventId + 1)];
3648-
Array.Copy(eventData, newValues, eventData.Length);
3648+
Array.Copy(eventData, 0, newValues, 0, eventData.Length);
36493649
eventData = newValues;
36503650
}
36513651

@@ -3684,7 +3684,7 @@ private static void TrimEventDescriptors(ref EventMetadata[] eventData)
36843684
if (eventData.Length - idx > 2) // allow one wasted slot.
36853685
{
36863686
EventMetadata[] newValues = new EventMetadata[idx + 1];
3687-
Array.Copy(eventData, newValues, newValues.Length);
3687+
Array.Copy(eventData, 0, newValues, 0, newValues.Length);
36883688
eventData = newValues;
36893689
}
36903690
}

src/System.IO/src/System/IO/BufferedStream.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private void EnsureShadowBufferAllocated()
134134
return;
135135

136136
byte[] shadowBuffer = new byte[Math.Min(_bufferSize + _bufferSize, MaxShadowBufferSize)];
137-
Array.Copy(_buffer, 0, shadowBuffer, 0, _writePos);
137+
Buffer.BlockCopy(_buffer, 0, shadowBuffer, 0, _writePos);
138138
_buffer = shadowBuffer;
139139
}
140140

@@ -416,7 +416,7 @@ private int ReadFromBuffer(byte[] array, int offset, int count)
416416

417417
if (readbytes > count)
418418
readbytes = count;
419-
Array.Copy(_buffer, _readPos, array, offset, readbytes);
419+
Buffer.BlockCopy(_buffer, _readPos, array, offset, readbytes);
420420
_readPos += readbytes;
421421

422422
return readbytes;
@@ -683,7 +683,7 @@ private void WriteToBuffer(byte[] array, ref int offset, ref int count)
683683
return;
684684

685685
EnsureBufferAllocated();
686-
Array.Copy(array, offset, _buffer, _writePos, bytesToWrite);
686+
Buffer.BlockCopy(array, offset, _buffer, _writePos, bytesToWrite);
687687

688688
_writePos += bytesToWrite;
689689
count -= bytesToWrite;
@@ -825,7 +825,7 @@ public override void Write(byte[] array, int offset, int count)
825825
if (totalUserbytes <= (_bufferSize + _bufferSize) && totalUserbytes <= MaxShadowBufferSize)
826826
{
827827
EnsureShadowBufferAllocated();
828-
Array.Copy(array, offset, _buffer, _writePos, count);
828+
Buffer.BlockCopy(array, offset, _buffer, _writePos, count);
829829
_stream.Write(_buffer, 0, totalUserbytes);
830830
_writePos = 0;
831831
return;
@@ -977,7 +977,7 @@ private async Task WriteToUnderlyingStreamAsync(byte[] array, int offset, int co
977977
if (totalUserBytes <= (_bufferSize + _bufferSize) && totalUserBytes <= MaxShadowBufferSize)
978978
{
979979
EnsureShadowBufferAllocated();
980-
Array.Copy(array, offset, _buffer, _writePos, count);
980+
Buffer.BlockCopy(array, offset, _buffer, _writePos, count);
981981

982982
await _stream.WriteAsync(_buffer, 0, totalUserBytes, cancellationToken).ConfigureAwait(false);
983983
_writePos = 0;

src/System.Net.Http/src/System/Net/Http/Unix/CurlHandler.CurlResponseMessage.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public override Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancel
282282
if (_remainingDataCount > 0)
283283
{
284284
int bytesToCopy = Math.Min(count, _remainingDataCount);
285-
Array.Copy(_remainingData, _remainingDataOffset, buffer, offset, bytesToCopy);
285+
Buffer.BlockCopy(_remainingData, _remainingDataOffset, buffer, offset, bytesToCopy);
286286

287287
_remainingDataOffset += bytesToCopy;
288288
_remainingDataCount -= bytesToCopy;

src/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemNetworkInterface.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ public override PhysicalAddress GetPhysicalAddress()
173173
{
174174
byte[] newAddr = new byte[_addressLength];
175175

176-
// Array.Copy only supports int and long while addressLength is uint (see IpAdapterAddresses).
176+
// Buffer.BlockCopy only supports int while addressLength is uint (see IpAdapterAddresses).
177177
// Will throw OverflowException if addressLength > Int32.MaxValue.
178-
Array.Copy(_physicalAddress, 0, newAddr, 0, checked((int)_addressLength));
178+
Buffer.BlockCopy(_physicalAddress, 0, newAddr, 0, checked((int)_addressLength));
179179
return new PhysicalAddress(newAddr);
180180
}
181181

src/System.Net.Ping/src/System/Net/NetworkInformation/Ping.Unix.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private async Task<PingReply> SendIcmpEchoRequestOverRawSocket(IPAddress address
113113
int dataOffset = ipHeaderLength + IcmpHeaderLengthInBytes;
114114
// We want to return a buffer with the actual data we sent out, not including the header data.
115115
byte[] dataBuffer = new byte[bytesReceived - dataOffset];
116-
Array.Copy(receiveBuffer, dataOffset, dataBuffer, 0, dataBuffer.Length);
116+
Buffer.BlockCopy(receiveBuffer, dataOffset, dataBuffer, 0, dataBuffer.Length);
117117

118118
IPStatus status = isIpv4
119119
? IcmpV4MessageConstants.MapV4TypeToIPStatus(type, code)

src/System.Net.Sockets/src/System/Net/Sockets/Socket.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4116,7 +4116,7 @@ internal Socket EndAccept(out byte[] buffer, IAsyncResult asyncResult)
41164116

41174117
Socket socket = EndAccept(out innerBuffer, out bytesTransferred, asyncResult);
41184118
buffer = new byte[bytesTransferred];
4119-
Array.Copy(innerBuffer, 0, buffer, 0, bytesTransferred);
4119+
Buffer.BlockCopy(innerBuffer, 0, buffer, 0, bytesTransferred);
41204120
return socket;
41214121
}
41224122

src/System.Private.DataContractSerialization/src/System/Xml/XmlBaseReader.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1370,9 +1370,9 @@ private int ReadBytes(Encoding encoding, int byteBlock, int charBlock, byte[] bu
13701370
if (_trailByteCount > 0)
13711371
{
13721372
int actual = Math.Min(_trailByteCount, byteCount);
1373-
Array.Copy(_trailBytes, 0, buffer, offset, actual);
1373+
Buffer.BlockCopy(_trailBytes, 0, buffer, offset, actual);
13741374
_trailByteCount -= actual;
1375-
Array.Copy(_trailBytes, actual, _trailBytes, 0, _trailByteCount);
1375+
Buffer.BlockCopy(_trailBytes, actual, _trailBytes, 0, _trailByteCount);
13761376
return actual;
13771377
}
13781378
XmlNodeType nodeType = _node.NodeType;
@@ -1440,9 +1440,9 @@ private int ReadBytes(Encoding encoding, int byteBlock, int charBlock, byte[] bu
14401440
_trailBytes = new byte[3];
14411441
_trailByteCount = encoding.GetBytes(chars, 0, charCount, _trailBytes, 0);
14421442
int actual = Math.Min(_trailByteCount, byteCount);
1443-
Array.Copy(_trailBytes, 0, buffer, offset, actual);
1443+
Buffer.BlockCopy(_trailBytes, 0, buffer, offset, actual);
14441444
_trailByteCount -= actual;
1445-
Array.Copy(_trailBytes, actual, _trailBytes, 0, _trailByteCount);
1445+
Buffer.BlockCopy(_trailBytes, actual, _trailBytes, 0, _trailByteCount);
14461446
return actual;
14471447
}
14481448
else

src/System.Private.DataContractSerialization/src/System/Xml/XmlStreamNodeWriter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ unsafe protected int UnsafeGetUTF8Chars(char* chars, int charCount, byte[] buffe
467467
string tmp = new string(charsStart, 0, (int)(chars - charsStart));
468468
byte[] newBytes = _encoding != null ? _encoding.GetBytes(tmp) : s_UTF8Encoding.GetBytes(tmp);
469469
int toCopy = Math.Min(newBytes.Length, (int)(bytesMax - bytes));
470-
Array.Copy(newBytes, 0, buffer, (int)(bytes - _bytes) + offset, toCopy);
470+
Buffer.BlockCopy(newBytes, 0, buffer, (int)(bytes - _bytes) + offset, toCopy);
471471

472472
bytes += toCopy;
473473

src/System.Reflection.Metadata/src/System/Reflection/BlobBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public byte[] ToArray(int start, int byteCount)
305305
break;
306306
}
307307

308-
Array.Copy(chunk._buffer, Math.Max(start - chunkStartPosition, 0), result, resultOffset, bytesToCopy);
308+
Buffer.BlockCopy(chunk._buffer, Math.Max(start - chunkStartPosition, 0), result, resultOffset, bytesToCopy);
309309

310310
resultOffset += bytesToCopy;
311311
}

src/System.Reflection.Metadata/src/System/Reflection/BlobWriter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public byte[] ToArray(int start, int byteCount)
108108
BlobUtilities.ValidateRange(Length, start, byteCount);
109109

110110
var result = new byte[byteCount];
111-
Array.Copy(_buffer, _start + start, result, 0, byteCount);
111+
Buffer.BlockCopy(_buffer, _start + start, result, 0, byteCount);
112112
return result;
113113
}
114114

src/System.Runtime.WindowsRuntime/src/System/IO/BufferedStream.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private void EnsureShadowBufferAllocated()
170170
return;
171171

172172
Byte[] shadowBuffer = new Byte[Math.Min(_bufferSize + _bufferSize, MaxShadowBufferSize)];
173-
Array.Copy(_buffer, 0, shadowBuffer, 0, _writePos);
173+
Buffer.BlockCopy(_buffer, 0, shadowBuffer, 0, _writePos);
174174
_buffer = shadowBuffer;
175175
}
176176

@@ -485,7 +485,7 @@ private Int32 ReadFromBuffer(Byte[] array, Int32 offset, Int32 count)
485485

486486
if (readBytes > count)
487487
readBytes = count;
488-
Array.Copy(_buffer, _readPos, array, offset, readBytes);
488+
Buffer.BlockCopy(_buffer, _readPos, array, offset, readBytes);
489489
_readPos += readBytes;
490490

491491
return readBytes;
@@ -842,7 +842,7 @@ private void WriteToBuffer(Byte[] array, ref Int32 offset, ref Int32 count)
842842
return;
843843

844844
EnsureBufferAllocated();
845-
Array.Copy(array, offset, _buffer, _writePos, bytesToWrite);
845+
Buffer.BlockCopy(array, offset, _buffer, _writePos, bytesToWrite);
846846

847847
_writePos += bytesToWrite;
848848
count -= bytesToWrite;
@@ -986,7 +986,7 @@ public override void Write(Byte[] array, Int32 offset, Int32 count)
986986
if (totalUserBytes <= (_bufferSize + _bufferSize) && totalUserBytes <= MaxShadowBufferSize)
987987
{
988988
EnsureShadowBufferAllocated();
989-
Array.Copy(array, offset, _buffer, _writePos, count);
989+
Buffer.BlockCopy(array, offset, _buffer, _writePos, count);
990990
_stream.Write(_buffer, 0, totalUserBytes);
991991
_writePos = 0;
992992
return;

src/System.Runtime.WindowsRuntime/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBuffer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static IBuffer Create(Byte[] data, Int32 offset, Int32 length, Int32 capa
6565
Contract.EndContractBlock();
6666

6767
Byte[] underlyingData = new Byte[capacity];
68-
Array.Copy(data, offset, underlyingData, 0, length);
68+
Buffer.BlockCopy(data, offset, underlyingData, 0, length);
6969
return new WindowsRuntimeBuffer(underlyingData, 0, length, capacity);
7070
}
7171

0 commit comments

Comments
 (0)