Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Use Buffer.BlockCopy with byte[]s #6103

Merged
merged 1 commit into from
Feb 15, 2016

Conversation

stephentoub
Copy link
Member

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 (in particular for small arrays).

This commit replaces usage of Array.Copy(byte[], ...) in corefx with Buffer.BlockCopy(byte[], ...). A lot of places were already using BlockCopy.

(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.)

cc:
@davidsh for networking
@saurabh500 for data
@bartonjs for security
@ianhays for I/O

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.)
@davidsh
Copy link
Contributor

davidsh commented Feb 14, 2016

LGTM for networking

@bartonjs
Copy link
Member

Security (including parts in Common) LGTM

@@ -186,7 +186,7 @@ public char[] Value

default:
buffer = new char[_lCurLen];
Array.Copy(m_rgchBuf, buffer, (int)_lCurLen);
Array.Copy(m_rgchBuf, 0, buffer, 0, (int)_lCurLen);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you leave this out to use Array.Copy intentionally?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was only changing those using byte[] to use BlockCopy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah OK.

@saurabh500
Copy link
Contributor

LGTM from data

stephentoub added a commit that referenced this pull request Feb 15, 2016
@stephentoub stephentoub merged commit 59f4427 into dotnet:master Feb 15, 2016
@stephentoub stephentoub deleted the buffer_blockcopy branch February 15, 2016 18:10
bgrainger added a commit to mysql-net/MySqlConnector that referenced this pull request Apr 22, 2016
@karelz karelz modified the milestone: 1.0.0-rtm Dec 3, 2016
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants