Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Buffer.BlockCopy with byte[] #1366

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,7 @@ private bool TryGetBytesInternal(int i, long dataIndex, byte[] buffer, int buffe
cbytes = length;
}

Array.Copy(data, ndataIndex, buffer, bufferIndex, cbytes);
Buffer.BlockCopy(data, ndataIndex, buffer, bufferIndex, cbytes);
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ private void ValidateActiveOnConnection(SqlInternalConnection connection)
private Guid GetGlobalTxnIdentifierFromToken()
{
byte[] txnGuid = new byte[16];
Array.Copy(_connection.PromotedDTCToken, _globalTransactionsTokenVersionSizeInBytes /* Skip the version */, txnGuid, 0, txnGuid.Length);
Buffer.BlockCopy(_connection.PromotedDTCToken, _globalTransactionsTokenVersionSizeInBytes /* Skip the version */, txnGuid, 0, txnGuid.Length);
return new Guid(txnGuid);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ private byte[] PrepareByteBuffer(int numberOfChars, out int byteBufferUsed)
{
// Otherwise, copy over the leftover buffer
byteBuffer = new byte[byteBufferSize];
Array.Copy(_leftOverBytes, byteBuffer, _leftOverBytes.Length);
Buffer.BlockCopy(_leftOverBytes, 0, byteBuffer, 0,_leftOverBytes.Length);
byteBufferUsed = _leftOverBytes.Length;
}
}
Expand Down Expand Up @@ -411,7 +411,7 @@ private int DecodeBytesToChars(byte[] inBuffer, int inBufferCount, char[] outBuf
if ((!completed) && (bytesUsed < inBufferCount))
{
_leftOverBytes = new byte[inBufferCount - bytesUsed];
Array.Copy(inBuffer, bytesUsed, _leftOverBytes, 0, _leftOverBytes.Length);
Buffer.BlockCopy(inBuffer, bytesUsed, _leftOverBytes, 0, _leftOverBytes.Length);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ override public int Read(byte[] buffer, int offset, int count)
cb = _cachedBytes[_currentArrayIndex].Length - _currentPosition;
if (cb > count)
cb = count;
Array.Copy(_cachedBytes[_currentArrayIndex], _currentPosition, buffer, offset, cb);
Buffer.BlockCopy(_cachedBytes[_currentArrayIndex], _currentPosition, buffer, offset, cb);

_currentPosition += cb;
count -= (int)cb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ public SqlBinary Adjust(SqlBinary value)
{
byte[] rgbValue = value.Value;
byte[] rgbNewValue = new byte[MaxLength];
Array.Copy(rgbValue, rgbNewValue, rgbValue.Length);
Buffer.BlockCopy(rgbValue, 0, rgbNewValue, 0, rgbValue.Length);
Array.Clear(rgbNewValue, rgbValue.Length, rgbNewValue.Length - rgbValue.Length);
return new SqlBinary(rgbNewValue);
}
Expand All @@ -1308,7 +1308,7 @@ public SqlBinary Adjust(SqlBinary value)
{
byte[] rgbValue = value.Value;
byte[] rgbNewValue = new byte[MaxLength];
Array.Copy(rgbValue, rgbNewValue, (int)MaxLength);
Buffer.BlockCopy(rgbValue,0, rgbNewValue,0, (int)MaxLength);
value = new SqlBinary(rgbNewValue);
}

Expand Down Expand Up @@ -1400,7 +1400,7 @@ public SqlBytes Adjust(SqlBytes value)
if (value.MaxLength < MaxLength)
{
byte[] rgbNew = new byte[MaxLength];
Array.Copy(value.Buffer, rgbNew, (int)oldLength);
Buffer.BlockCopy(value.Buffer, 0,rgbNew,0, (int)oldLength);
value = new SqlBytes(rgbNew);
}

Expand Down Expand Up @@ -1929,7 +1929,7 @@ public byte[] Adjust(byte[] value)
if (value.Length < MaxLength)
{
byte[] rgbNewValue = new byte[MaxLength];
Array.Copy(value, rgbNewValue, value.Length);
Buffer.BlockCopy(value, 0, rgbNewValue, 0, value.Length);
Array.Clear(rgbNewValue, value.Length, (int)rgbNewValue.Length - value.Length);
return rgbNewValue;
}
Expand All @@ -1950,7 +1950,7 @@ public byte[] Adjust(byte[] value)
if (value.Length > MaxLength && Max != MaxLength)
{
byte[] rgbNewValue = new byte[MaxLength];
Array.Copy(value, rgbNewValue, (int)MaxLength);
Buffer.BlockCopy(value, 0, rgbNewValue, 0, (int)MaxLength);
value = rgbNewValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static long GetBytesConversion(SmiEventSink_Default sink, ITypedGettersV

length = CheckXetParameters(metaData.SqlDbType, metaData.MaxLength * sizeof(char), value.Length,
fieldOffset, buffer.Length, bufferOffset, length);
Array.Copy(value.Value, checked((int)fieldOffset), buffer, bufferOffset, length);
Buffer.BlockCopy(value.Value, checked((int)fieldOffset), buffer, bufferOffset, length);
return length;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static byte[] CreateBinaryTable(SqlConnection connection, string tableNa
while (position < data.Length)
{
int copyCount = Math.Min(pattern.Length, data.Length - position);
Array.Copy(pattern, 0, data, position, copyCount);
Buffer.BlockCopy(pattern, 0, data, position, copyCount);
position += copyCount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private int ReadInternal(byte[] buffer, int offset, int count)
}
if (_errorPos >= _pos && _errorPos < _pos + nRead)
throw new CustomStreamException();
Array.Copy(_data, _pos, buffer, offset, nRead);
Buffer.BlockCopy(_data, _pos, buffer, offset, nRead);
_pos += nRead;
return nRead;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public override void Write(byte[] buffer, int offset, int count)
if (packetDataToWrite > 0)
{
// Append new data to the end of the packet data
Array.Copy(buffer, bufferWrittenPosition + offset, _outgoingPacket, OutgoingPacketHeader.Length, packetDataToWrite);
Buffer.BlockCopy(buffer, bufferWrittenPosition + offset, _outgoingPacket, OutgoingPacketHeader.Length, packetDataToWrite);

// Register that we've written new data
bufferWrittenPosition += packetDataToWrite;
Expand Down